Module: LLT::Helpers::RomanNumerals
- Defined in:
- lib/llt/helpers/roman_numerals.rb
Class Method Summary collapse
-
.roman?(value) ⇒ Boolean
Uncapitalized numerals will NOT be detected atm.
-
.to_decimal(value) ⇒ Object
IV to 4.
-
.to_roman(value) ⇒ Object
4 to IV.
Class Method Details
.roman?(value) ⇒ Boolean
Uncapitalized numerals will NOT be detected atm.
12 13 14 |
# File 'lib/llt/helpers/roman_numerals.rb', line 12 def roman?(value) /^[CDILMVX]*$/.match(value) end |
.to_decimal(value) ⇒ Object
IV to 4
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/llt/helpers/roman_numerals.rb', line 30 def to_decimal(value) res = 0 numerals.each do |_, rom| while value.start_with?(rom) value = value[rom.length..-1] res += numerals.key(rom) end end res end |
.to_roman(value) ⇒ Object
4 to IV
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/llt/helpers/roman_numerals.rb', line 17 def to_roman(value) res = "" numerals.each do |dec, _| while value >= dec value -= dec res << numerals[dec] end end res end |