Class: Mods::Date::RomanNumeralYearFormat
- Inherits:
-
ExtractorDateFormat
- Object
- Mods::Date
- ExtractorDateFormat
- Mods::Date::RomanNumeralYearFormat
- Defined in:
- lib/mods/date.rb
Overview
Full-text extractor for dates encoded as Roman numerals
Direct Known Subclasses
Constant Summary collapse
- REGEX =
/^(?<year>[MCDLXVI]+)/
Instance Attribute Summary
Attributes inherited from Mods::Date
Class Method Summary collapse
Methods inherited from ExtractorDateFormat
Methods inherited from Mods::Date
#approximate?, #as_range, #encoding, #encoding?, #end?, from_element, #inferred?, #initialize, parse_date, #point, #qualifier, #questionable?, #single?, #start?, #text, #to_a, #type
Constructor Details
This class inherits a constructor from Mods::Date
Class Method Details
.cleanup(text) ⇒ Object
129 130 131 132 |
# File 'lib/mods/date.rb', line 129 def self.cleanup(text) matches = text.match(REGEX) roman_to_int(matches[:year].upcase).to_s end |
.roman_to_int(value) ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/mods/date.rb', line 134 def self.roman_to_int(value) value = value.dup map = { "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 } result = 0 map.each do |k,v| while value.index(k) == 0 result += v value.slice! k end end result end |