Module English::RomanNumerals
In: lib/more/facets/roman.rb

Contains methods to convert integers to roman numeral strings and vice-versa.

Methods

Constants

MAX = 3999   The largest integer representable as a roman numerable by this module.
REGEXP = /^M*(D?C{0,3}|C[DM])(L?X{0,3}|X[LC])(V?I{0,3}|I[VX])$/i   Stolen from O‘Reilly‘s Perl Cookbook 6.23. Regular Expression Grabbag.
SYMBOLS = [ "M", "D", "C", "L", "X", "V", "I" ]  
NUMBERS = [ 1000, 500, 100, 50, 10, 5, 1 ]
TABLE = Hash[*SYMBOLS.zip(NUMBERS).flatten]   Maps roman numeral digits to their integer values.
  {
    'I' => 1,
    'V' => 5,
    'X' => 10,
    'L' => 50,
    'C' => 100,
    'D' => 500,
    'M' => 1000,
  }
PAIR_SYMBOLS = [ "CM", "CD", "XC", "XL", "IX", "IV", "I" ]  
PAIR_NUMBERS = [ 900, 400, 90, 40, 9, 4, 1 ]
PAIR_TABLE = Hash[*PAIR_SYMBOLS.zip(PAIR_NUMBERS).flatten]   {
  'CM' => 900,
  'CD' => 400,
  'XC' => 90,
  'XL' => 40,
  'IX' => 9,
  'IV' => 4

}

LOOKUP = TABLE.invert.merge(PAIR_TABLE.invert)  

External Aliases

from_integer -> roman
to_integer -> arabic

Public Class methods

Converts integer to a roman numeral.

Returns true iif string is a roman numeral.

Converts roman_string, a roman numeral, to an integer

[Validate]