Skip to content

Instantly share code, notes, and snippets.

@geoffgarside
Created August 20, 2008 14:11
Show Gist options
  • Save geoffgarside/6369 to your computer and use it in GitHub Desktop.
Save geoffgarside/6369 to your computer and use it in GitHub Desktop.
module Numerology
Standard = {
'1' => 1, '4' => 4, '7' => 7,
'2' => 2, '5' => 5, '8' => 8,
'3' => 3, '6' => 6, '9' => 9,
'A' => 1, 'J' => 1, 'S' => 1,
'B' => 2, 'K' => 2, 'T' => 2,
'C' => 3, 'L' => 3, 'U' => 3,
'D' => 4, 'M' => 4, 'V' => 4,
'E' => 5, 'N' => 5, 'W' => 5,
'F' => 6, 'O' => 6, 'X' => 6,
'G' => 7, 'P' => 7, 'Y' => 7,
'H' => 8, 'Q' => 8, 'Z' => 8,
'I' => 9, 'R' => 9
}
Chaldean = {
'1' => 1, '4' => 4, '7' => 7,
'2' => 2, '5' => 5, '8' => 8,
'3' => 3, '6' => 6, '9' => 9,
'A' => 1, 'J' => 1, 'S' => 3,
'B' => 2, 'K' => 2, 'T' => 4,
'C' => 3, 'L' => 3, 'U' => 6,
'D' => 4, 'M' => 4, 'V' => 6,
'E' => 5, 'N' => 5, 'W' => 6,
'F' => 8, 'O' => 7, 'X' => 5,
'G' => 3, 'P' => 8, 'Y' => 1,
'H' => 5, 'Q' => 1, 'Z' => 7,
'I' => 1, 'R' => 2
}
def self.calculate(str, mapping = Standard)
sum = str.gsub(/[^a-z]/,'').upcase.split(//).inject(0) do |v,l|
v += mapping[l] || 0
end % 9
sum == 0 ? 9 : sum
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment