Module: Romanic::RomanicIntegers

Defined in:
lib/romanic/romanic_integers.rb

Instance Method Summary collapse

Instance Method Details

#to_romanObject

Convert integers to roman numerals



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/romanic/romanic_integers.rb', line 4

def to_roman
  number = self
  return nil unless number.class == Fixnum
  return nil unless number > 0 and number < 5000
  ROMAN_LOOKUP.inject("") do |result, (roman, arabic)|
    # divmod() returns array of quotient and modulus
    count, number = number.divmod(arabic)
    result << (roman * count)
    result
  end
end