class TwoDigits

Attributes

num[R]

Public Class Methods

new(num) click to toggle source
# File lib/digits/two_digits.rb, line 15
def initialize(num)
  @num = num
end
run(num) click to toggle source
# File lib/digits/two_digits.rb, line 3
def self.run(num)
  new(num).in_words
end

Public Instance Methods

in_words() click to toggle source
# File lib/digits/two_digits.rb, line 7
def in_words
  less_than_20? ? less_than_20 : more_than_19 
end

Private Instance Methods

complex_tens() click to toggle source
# File lib/digits/two_digits.rb, line 35
def complex_tens
  [simple_tens, single_digits(num_mod(10))].join('-')
end
less_than_20() click to toggle source
# File lib/digits/two_digits.rb, line 23
def less_than_20 
  numbers_in_words['tenss'][num_mod(10)]
end
less_than_20?() click to toggle source
# File lib/digits/two_digits.rb, line 19
def less_than_20?
  num < 20
end
more_than_19() click to toggle source
# File lib/digits/two_digits.rb, line 27
def more_than_19
  num_mod(10).zero? ? simple_tens : complex_tens
end
simple_tens() click to toggle source
# File lib/digits/two_digits.rb, line 31
def simple_tens
  numbers_in_words['tens'][num/10]
end