class NumerisRomanis

Constants

MAP

Public Class Methods

new() click to toggle source
# File lib/numeris_romanis.rb, line 7
def initialize
  @romans = {}
  (1..3999).each do |number|
    @romans[number] = roman_for(number)
  end
end

Public Instance Methods

to_decimal(roman) click to toggle source
# File lib/numeris_romanis.rb, line 18
def to_decimal(roman)
  @romans.key(roman)
end
to_roman(value) click to toggle source
# File lib/numeris_romanis.rb, line 14
def to_roman(value)
  @romans[value]
end

Private Instance Methods

roman_for(value) click to toggle source
# File lib/numeris_romanis.rb, line 24
def roman_for(value)
  conversion = ''
  MAP.each do |decimal, roman|
    result = value.divmod(decimal)
    conversion << roman * result.first
    value = result.last
  end
  conversion
end