20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/number_to_words.rb', line 20
def to_words
words = Array.new
number = self.to_i
if number.to_i == 0
words << self.zero_string
else
number = number.to_s.rjust(33,'0')
groups = number.scan(/.{3}/).reverse
words << number_to_words(groups[0])
(1..10).each do |number|
if groups[number].to_i > 0
case number
when 1,3,5,7,9
words << "mil"
else
words << (groups[number].to_i > 1 ? "#{self.quantities[number]}ones" : "#{self.quantities[number]}ón")
end
words << number_to_words(groups[number])
end
end
end
return "#{words.reverse.join(' ')}"
end
|