Module: ToWords::Utils
Constant Summary
ToWords::UnderHundred::UNDER_HUNDRED
Instance Method Summary
collapse
Instance Method Details
#check_sign(num) ⇒ Object
23
24
25
|
# File 'lib/to_words/utils.rb', line 23
def check_sign(num)
num < 0 ? [num.abs, "negative "] : [num, ""]
end
|
#higher_than_hundred(hundred, remaining, counter) ⇒ Object
14
15
16
17
18
19
20
21
|
# File 'lib/to_words/utils.rb', line 14
def higher_than_hundred(hundred, remaining, counter)
century = UNDER_HUNDRED[hundred]
if remaining != 0
return century + " Hundred " + UNDER_HUNDRED[remaining] if counter != 0
return century + " Hundred and " + UNDER_HUNDRED[remaining]
end
return century + " Hundred " if remaining == 0
end
|
#numerical?(num) ⇒ Boolean
27
28
29
30
31
|
# File 'lib/to_words/utils.rb', line 27
def numerical?(num)
Integer(num)
rescue
raise "A whole number is expected"
end
|
#result_below_one_thousand(num, counter) ⇒ Object
7
8
9
10
11
12
|
# File 'lib/to_words/utils.rb', line 7
def result_below_one_thousand(num, counter)
hundred, remaining = num.divmod(100)
return higher_than_hundred(hundred, remaining, counter) if hundred != 0
UNDER_HUNDRED[remaining] if hundred == 0 && remaining != 0
end
|