Module: RomanNumerals
- Included in:
- NumberTo
- Defined in:
- lib/modules/roman_numerals.rb
Overview
adapted without any substanial changes from github.com/AndrewVos/roman-numerals
Constant Summary collapse
- BASE_DIGITS =
{ 1 => 'I', 4 => 'IV', 5 => 'V', 9 => 'IX', 10 => 'X', 40 => 'XL', 50 => 'L', 90 => 'XC', 100 => 'C', 400 => 'CD', 500 => 'D', 900 => 'CM', 1000 => 'M' }
Instance Method Summary collapse
Instance Method Details
#to_lower_roman(value) ⇒ Object
30 31 32 |
# File 'lib/modules/roman_numerals.rb', line 30 def to_lower_roman(value) to_upper_roman(value).downcase end |
#to_upper_roman(value) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/modules/roman_numerals.rb', line 19 def to_upper_roman(value) result = '' BASE_DIGITS.keys.reverse.each do |decimal| while value >= decimal value -= decimal result += BASE_DIGITS[decimal] end end result end |