class FiveDigits

Attributes

num[R]

Public Class Methods

new(num) click to toggle source
# File lib/digits/five_digits.rb, line 15
def initialize(num)
  @num = num
end
run(num) click to toggle source
# File lib/digits/five_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/five_digits.rb, line 7
def in_words
  num_mod(10000).zero? ? simple_ten_thous : complex_ten_thous
end

Private Instance Methods

complex_ten_thous() click to toggle source
# File lib/digits/five_digits.rb, line 35
def complex_ten_thous
  [simple_ten_thous, rest].join('-')
end
first_two_digits() click to toggle source
# File lib/digits/five_digits.rb, line 19
def first_two_digits
  TwoDigits.new(in_array[0,2].join.to_i).in_english
end
rest() click to toggle source
# File lib/digits/five_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/five_digits.rb, line 23
def rest_digits
  in_array[-3..-1].join.to_i
end
simple_ten_thous() click to toggle source
# File lib/digits/five_digits.rb, line 31
def simple_ten_thous
  [first_two_digits, prefix(power_of_ten)].join('-')
end