Class | Integer |
In: |
lib/facets/core-uncommon/facets/integer/roman.rb
|
Parent: | Object |
ROMAN_MAX | = | 3999 unless const_defined?(:ROMAN_MAX) | ||
ROMAN_VALUES | = | [ ["M", 1000], ["CM", 900], ["D", 500], ["CD", 400], ["C", 100], ["XC", 90], ["L", 50], ["XL", 40], ["X", 10], ["IX", 9], ["V", 5], ["IV", 4], ["I", 1] |
Converts this integer to a roman numeral.
NOTE: This is not (presently) a common core extension and is not loaded automatically when using require ‘facets‘.
# File lib/facets/core-uncommon/facets/integer/roman.rb, line 27 def roman int = self #return nil if integer > ROMAN_MAX return "-#{(-int).roman}" if int < 0 return "" if int == 0 ROMAN_VALUES.each do |(i, v)| return(i + (int-v).roman) if v <= int end end