Module: English::Numerals

Included in:
Integer
Defined in:
lib/gems/english-0.3.1/lib/english/numerals.rb

Overview

:nodoc:

Constant Summary collapse

Ones =
%w[ zero one two three four five six seven eight nine ]
Teen =
%w[ ten eleven twelve thirteen fourteen fifteen
sixteen seventeen eighteen nineteen ]
Tens =
%w[ zero ten twenty thirty forty fifty
sixty seventy eighty ninety ]
Mega =
%w[ none thousand million billion ]

Instance Method Summary collapse

Instance Method Details

#name(integer) ⇒ Object

Convert an integer to the english spelling of that number.



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/gems/english-0.3.1/lib/english/numerals.rb', line 26

def name(integer)
  places = integer.to_i.to_s.split(//).collect{|s| s.to_i}.reverse
  name = []
  ((places.length + 2) / 3).times do |p|
    strings = Numerals.trio(places[p * 3, 3])
    name.push(Mega[p]) if strings.length > 0 and p > 0
    name += strings
  end
  name.push(Ones[0]) unless name.length > 0
  name.reverse.join(" ")
end