Module: ToRupees

Includes:
Divisions, UnderHundred, Utils
Included in:
INTEGER_KLASS
Defined in:
lib/to_rupees.rb,
lib/to_rupees/utils.rb,
lib/to_rupees/version.rb,
lib/to_rupees/divisions.rb,
lib/to_rupees/under_hundred.rb

Defined Under Namespace

Modules: Divisions, UnderHundred, Utils Classes: Error, INTEGER_KLASS

Constant Summary collapse

VERSION =
"0.1.3"

Constants included from UnderHundred

UnderHundred::UNDER_HUNDRED

Constants included from Divisions

Divisions::DIVISIONS

Instance Method Summary collapse

Methods included from Utils

#higher_than_hundred, #numerical?, #result_below_one_thousand

Instance Method Details

#to_rupeesObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/to_rupees.rb', line 13

def to_rupees
  num = numerical?(self)
  in_words = ''
  if num <= 100
    in_words = UNDER_HUNDRED[num]
  else
    counter  = 0
    result   = []
    num, remaining = num.divmod(1000)
    temp_result    = result_below_one_thousand(remaining, counter)
    result << temp_result + " " + DIVISIONS[counter] + " " if temp_result
    counter += 1
    while num != 0
      num, remaining = num.divmod(100)
      temp_result = result_below_one_thousand(remaining, counter)
      result << temp_result + " " + DIVISIONS[counter] + " " if temp_result
      counter += 1
    end
    in_words = result.reverse.join(", ").rstrip
  end
  (in_words + " rupee#{numerical?(self) > 1 ? 's' : ''}").titleize
end