Class: Roman
- Inherits:
-
NumeralBase
- Object
- NumeralBase
- Roman
- Defined in:
- lib/numerify/converters/roman.rb
Overview
A class to convert to Roman numerals.
Constant Summary collapse
- NUMERALS =
{ 0 => "", 1 => "I", 5 => "V", 10 => "X", 50 => "L", 100 => "C", 500 => "D", 1000 => "M" }.freeze
Instance Method Summary collapse
Instance Method Details
#convert(arabic_number_string) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/numerify/converters/roman.rb', line 18 def convert(arabic_number_string) arabic_number_string = arabic_number_string.to_s.strip return convert_to_roman_below_two_thousand(arabic_number_string) if arabic_number_string.to_i < 2000 ("M" * arabic_number_string.slice(0...-3).to_i) + convert_to_roman_below_two_thousand(arabic_number_string.slice(-3, 3)) end |