Class: Mods::Date::RomanNumeralCenturyFormat

Inherits:
RomanNumeralYearFormat show all
Defined in:
lib/mods/date.rb

Overview

Full-text extractor for centuries encoded as Roman numerals; sometimes centuries are given as e.g. xvith, hence the funny negative look-ahead assertion

Constant Summary collapse

REGEX =
/(?<![a-z])(?<century>[xvi]+)(?![a-su-z])/

Instance Attribute Summary

Attributes inherited from Mods::Date

#date, #xml

Class Method Summary collapse

Methods inherited from RomanNumeralYearFormat

roman_to_int

Methods inherited from ExtractorDateFormat

supports?

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

.munge_to_yyyy(text) ⇒ Object


165
166
167
168
# File 'lib/mods/date.rb', line 165

def self.munge_to_yyyy(text)
  value = roman_to_int(text.upcase)
  (value - 1).to_s.rjust(2, "0") + 'XX'
end

.normalize_to_edtf(text) ⇒ Object


160
161
162
163
# File 'lib/mods/date.rb', line 160

def self.normalize_to_edtf(text)
  matches = text.match(REGEX)
  munge_to_yyyy(matches[:century])
end