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 =
/(?<![A-Za-z\.])(?<year>[MCDLXVI\.]+)(?![A-Za-z])/
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, #key?, parse_date, #point, #precision, #qualifier, #questionable?, #single?, #start?, #text, #to_a, #type
Constructor Details
This class inherits a constructor from Mods::Date
Class Method Details
.normalize_to_edtf(text) ⇒ Object
136 137 138 139 |
# File 'lib/mods/date.rb', line 136 def self.normalize_to_edtf(text) matches = text.match(REGEX) roman_to_int(matches[:year].upcase).to_s end |
.roman_to_int(value) ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/mods/date.rb', line 141 def self.roman_to_int(value) value = value.tr('.', '') 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 |