Module: ToRupees::Utils

Includes:
UnderHundred
Included in:
ToRupees
Defined in:
lib/to_rupees/utils.rb

Constant Summary

Constants included from UnderHundred

ToRupees::UnderHundred::UNDER_HUNDRED

Instance Method Summary collapse

Instance Method Details

#higher_than_hundred(hundred, remaining, counter) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/to_rupees/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

Returns:

  • (Boolean)


23
24
25
26
27
# File 'lib/to_rupees/utils.rb', line 23

def numerical?(num)
  Integer(num)
rescue
  raise "A numeric is expected"
end

#result_below_one_thousand(num, counter) ⇒ Object



7
8
9
10
11
12
# File 'lib/to_rupees/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