class ThreeDigits

Attributes

num[R]

Public Class Methods

new(num) click to toggle source
# File lib/digits/three_digits.rb, line 15
def initialize(num)
  @num = num
end
run(num) click to toggle source
# File lib/digits/three_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/three_digits.rb, line 7
def in_words
  num_mod(100).zero? ? simple_hundreds : complex_hundreds
end

Private Instance Methods

complex_hundreds() click to toggle source
# File lib/digits/three_digits.rb, line 35
def complex_hundreds
  [first_digit, prefix(power_of_ten), rest].join('-')
end
first_digit() click to toggle source
# File lib/digits/three_digits.rb, line 19
def first_digit
  single_digits(in_array[0].to_i)
end
rest() click to toggle source
# File lib/digits/three_digits.rb, line 27
def rest
  rest_digits < 10 ? single_digits(rest_digits) : Digits.new(rest_digits).in_english
end
rest_digits() click to toggle source
# File lib/digits/three_digits.rb, line 23
def rest_digits
  in_array[1..-1].join.to_i
end
simple_hundreds() click to toggle source
# File lib/digits/three_digits.rb, line 31
def simple_hundreds
  [first_digit, prefix(power_of_ten)].join('-')
end