Method: ToWords#to_words

Defined in:
lib/to_words.rb

#to_wordsObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# 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