class HumaneInteger
Constants
- Mega
- Ones
- Teen
- Tens
Private Class Methods
trio(places)
click to toggle source
# File lib/humane_integer.rb, line 28 def self.trio(places) strings = [] if places[1] == 1 strings.push(Teen[places[0]]) elsif places[1] and places[1] > 0 strings.push(places[0] == 0 ? Tens[places[1]] : "#{Tens[places[1]]}-#{Ones[places[0]]}") elsif places[0] > 0 strings.push(Ones[places[0]]) end if places[2] and places[2] > 0 strings.push("hundred", Ones[places[2]]) end strings end
Public Instance Methods
to_english()
click to toggle source
# File lib/humane_integer.rb, line 14 def to_english places = to_s.split(//).collect {|s| s.to_i}.reverse name = [] ((places.length + 2) / 3).times do |p| strings = self.class.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