So it’s been a long time since I’ve posted anything so I thought I’d give an update so that there is something here.
I love my job to death! I work with awesome people and have a lot of cool stuff to do. I’m also climbing three times a week, which doesn’t leave me with a lot of time to code or be at home. When I am home I’m working on a STOMP library for the Arduino Ethernet Shield.
The STOMP library is going to be used in part of a home automation system my partner and I are working on. I say “working on” because she’s just as busy as I am and doesn’t have much time to work on all of the projects she’s got on the go.
So I’m still around and just really busy!
This bit of code is the Soundex algorithm based on some C written by a friend of mine (Hi Jen!). She writes really compact C (read: hard to read) and it took me a long time to understand what the code she wrote did.
So here is the annotated version of the code (correlates to the Rule numbers on Wikipedia).
RUBY:
-
class String
-
@@sem = [ 0,1,2,3,0,1,2,0,0,2,2,4,5,5,0,1,2,6,2,3,0,1,0,2,0,2 ] # Letter codes, Rule 3
-
-
def to_soundex
-
s = self.upcase
-
chars = s[1 .. s.size - 1].split(//) # Split the word into characters to encode
-
ret = s[0,1] # Rule 1
-
chars.each_index do |i|
-
c = chars[i]
-
next if ( c <'A' or c> 'Z' ) # Not a letter
-
next if i>0 and c == chars[i - 1] # Rule 4
-
d = @@sem[ c[0] - 'A'[0] ] # Encode it
-
ret += d.to_s unless d == 0 # Rule 2
-
end
-
ret += "0000" # Rule 5
-
ret[0..3] # Rule 5
-
end
-
end
It was fun to write and it works well.