Class: Wintr::Number

Inherits:
Object
  • Object
show all
Defined in:
lib/wintr/number.rb

Instance Method Summary collapse

Constructor Details

#initialize(number) ⇒ Number

Returns a new instance of Number.



6
7
8
# File 'lib/wintr/number.rb', line 6

def initialize(number)
  @number = number
end

Instance Method Details

#to_sObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/wintr/number.rb', line 10

def to_s
  return 'zero' if @number == 0

  word_array = []
  digit_array = @number.to_s.chars.to_a
  power_of_thousand = 0

  until digit_array == [] do
    digit_group = digit_array.pop(3)
    word_array.unshift(WeightedDigitGroup.new(digit_group, power_of_thousand).to_s)
    power_of_thousand += 1
  end
  WordArray.new(word_array).to_s
end