Finding and mapping Windows OLE object property values using Ruby
I learnt much of my Ruby doing stuff on Windows mainly because Windows was the majority platform in my day job and the platform I needed to get things done on.
In those days installing Ruby on Windows was more difficult than it is today ever since the wonderful folks over at RubyInstaller have made it such a doddle.
Ruby on Windows has always been considered something of a second class citizen in the Ruby family. But its really easy do some some very useful and powerful stuff: using Ruby with various Windows APIs has proved very productive for me.
It would be remiss of me, in a first post on using Ruby with Windows, not to tip my hat at David Mullet. Reading David’s excellent blog made me more than once expostulate “you can really do that so easily?”. Thank you David for teaching me to fish in the Ruby / Windows waters and giving me the steer on many topics.
Since then I’ve written quite a lot of Windows-specific code in Ruby including for Office (Excel, Outlook), WMI (the Swiss army knife of Windows APIs!) and (some) ADSI.
One of the tasks I’ve found myself doing often was needing to obtain the value of an OLE object’s (e.g the worksheets collection of an Excel workbook) property value and map the value (especially if it is a collection) to some more convenient Ruby form (e.g. “importing” the property into an instance of a class).
I’ve also wanted the mapping to be lazy: for example I didn’t want to have to read in all the emails in my Outlook inbox before I could process any of them. Although lazy enumeration could be done in Ruby 1.8, 1.9 brought “first class” (external) enumerators.
The code for a method to find an OLE object’s property value(s) and create a mapped enumerator is almost trivial.
Clojure, Emacs, SLIME and Swank on Ubuntu Precise 12.04
Why this combo?
I’ve been using jEdit for some time as my general purpose editor and “IDE” (especially for Ruby on Windows) so it was natural to start there for my first forays into Clojure, dropping out to e.g. Leiningen for a REPL.
But debugging Clojure is more of a challenge than, say, Ruby because the stack trace is a Java one and its not as easy to associate the Clojure source file and line number with entries in the stack trace.
Also, I’ve found introducing print statements (e.g. println) into functional code make its look far noisier than OO code to the point where I find it obfuscates what the code is doing. This is partly a matter of taste but to me functional code looks far more elegant and transitive when compared to imperative and anything that interrupts the flow is a distraction.
After reading around the Clojure community for a better solution, the combination of Emacs, SLIME and Swank (supported by Leiningen) appeared to offer a far richer development and debugging environment so I thought I’d give it a go.
Installing emacs from source on Ubuntu Precise 12.04
The heavy lifting for this recipe was taken from a post by Chris Perkins (thanks Chris!).
Install the Prereqs
1
sudo apt-get install autoconf automake texinfo libgtk2.0-dev libxpm-dev libjpeg-dev libgif-dev libtiff4-dev libncurses5 libncurses5-dev
Clone emacs repo (into /tmp in my example). This takes a while - emacs is surpisingly big!
1
2
3
cd /tmp
git clone https://github.com/emacsmirror/emacs.git
cd ./emacs
Pretty standard build process. All the compilations can take a while.
1
2
3
4
5
make distclean
./autogen.sh
./configure
make
sudo make install
Quick test:
1
emacs -Q
Just remains to learn how to use it properly …
First Post
The canonical blog first post using Octopress and Jekyll and hosted on Github