Class: Wintr::TwoDigitGroup

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

Constant Summary collapse

TEN_TO_NINETEEN =
{
  '10' => 'ten',
  '11' => 'eleven',
  '12' => 'twelve',
  '13' => 'thirteen',
  '14' => 'fourteen',
  '15' => 'fifteen',
  '16' => 'sixteen',
  '17' => 'seventeen',
  '18' => 'eighteen',
  '19' => 'nineteen'
}
TENS =
{
  '2' => 'twenty',
  '3' => 'thirty',
  '4' => 'forty',
  '5' => 'fifty',
  '6' => 'sixty',
  '7' => 'seventy',
  '8' => 'eighty',
  '9' => 'ninety'
}

Instance Method Summary collapse

Constructor Details

#initialize(tens, units) ⇒ TwoDigitGroup

Returns a new instance of TwoDigitGroup.



26
27
28
# File 'lib/wintr/two_digit_group.rb', line 26

def initialize(tens, units)
  @tens, @units = tens, units
end

Instance Method Details

#to_wObject



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/wintr/two_digit_group.rb', line 30

def to_w
  word_array = []

  if @tens == '1'
    TEN_TO_NINETEEN[@tens + @units]
  elsif @tens == '0' && @units == '0'
    ''
  else
    word_array << TENS[@tens]
    word_array << OneDigitGroup.new(@units).to_w
    WordArray.new(word_array).to_w
  end
end