Path: | lib/facets/core-uncommon/facets/integer/roman.rb |
Last Update: | Mon Sep 12 21:11:41 +0000 2011 |
Considers string a Roman numeral numeral, and converts it to the corresponding integer.
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 54 def roman roman = upcase raise unless roman? last = roman[-1,1] roman.reverse.split('').inject(0) do |result, c| if ROMAN_VALUES[c] < ROMAN_VALUES[last] result -= ROMAN_VALUES[c] else last = c result += ROMAN_VALUES[c] end end end