Module: ToWords
- Includes:
- Divisions, UnderHundred, Utils
- Included in:
- INTEGER_KLASS, String
- Defined in:
- lib/to_words.rb,
lib/to_words/utils.rb,
lib/to_words/version.rb,
lib/to_words/divisions.rb,
lib/to_words/under_hundred.rb
Defined Under Namespace
Modules: Divisions, UnderHundred, Utils
Constant Summary collapse
- VERSION =
"1.1.1"
Constants included from UnderHundred
Constants included from Divisions
Instance Method Summary collapse
Methods included from Utils
#check_sign, #higher_than_hundred, #numerical?, #result_below_one_thousand
Instance Method Details
#to_words ⇒ Object
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 |