Class: Fixnum

Inherits:
Object
  • Object
show all
Defined in:
lib/lydown/core_ext.rb

Constant Summary collapse

@@roman_digits =

Taken from github.com/AndrewVos/roman-numerals Copyright © 2011 Andrew Vos

{
  1000 => 'M',
  900  => 'CM',
  500  => 'D',
  400  => 'CD',
  100  => 'C',
  90   => 'XC',
  50   => 'L',
  40   => 'XL',
  10   => 'X',
  9    => 'IX',
  5    => 'V',
  4    => 'IV',
  1    => 'I'
}

Instance Method Summary collapse

Instance Method Details

#to_romanObject



197
198
199
200
201
202
203
204
205
206
207
# File 'lib/lydown/core_ext.rb', line 197

def to_roman
  result = ''
  value = self
  @@roman_digits.keys.each do |decimal|
    while value >= decimal
      value -= decimal
      result += @@roman_digits[decimal]
    end
  end
  result
end