module ToWords

Constants

VERSION

Public Instance Methods

to_words() click to toggle source
# File lib/to_words.rb, line 12
def to_words
  num = numerical?(self)
  num, sign = check_sign(num)
  return (sign + UNDER_HUNDRED[num]) if num <= 100
  counter = 0
  result = []
  while num != 0
    num, remaining = num.divmod(1000)
    temp_result = result_below_one_thousand(remaining, counter)
    result << temp_result + " " + DIVISIONS[counter] + " " if temp_result
    counter += 1
  end
  sign + result.reverse.join(", ").rstrip
end