module OrdinalWord
Public Class Methods
wordinalize(int)
click to toggle source
Takes Integer in range 1-99 and returns string with ordinal number converted to word. If invalid argument is passed, raises OrdinalWordError
with appropriate message.
# File lib/ordinal_word.rb, line 8 def self.wordinalize(int) raise OrdinalWordError.new("Argument is not an Integer.") unless int.is_a?(Integer) raise OrdinalWordError.new("Number is less than 1.") if int < 1 raise OrdinalWordError.new("Unfortunately, the module doesn't support numbers more than 99.") if int > 99 if @@ordinalize_hash.has_key?(int) return @@ordinalize_hash[int] else tens = int / 10 ones = int % 10 return @@cardinal_hash[tens*10] + '-' + @@ordinalize_hash[ones] end end