Class: CocinaDisplay::Dates::RomanNumeralCenturyFormat

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

Overview

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])/

Constants inherited from Date

Date::BCE_CHAR_SORT_MAP, Date::UNPARSABLE_VALUES

Instance Attribute Summary

Attributes inherited from Date

#cocina, #date, #type

Class Method Summary collapse

Methods inherited from RomanNumeralYearFormat

roman_to_int

Methods inherited from ExtractorDateFormat

supports?

Methods inherited from Date

#<=>, #approximate?, #as_range, #base_value, #decoded_value, #encoding, #encoding?, #end?, format_date, from_cocina, #inferred?, #initialize, #parsable?, parse_date, #parsed_date?, #precision, #primary?, #qualified?, #qualified_value, #qualifier, #questionable?, #sort_key, #start?, #to_a, #value

Constructor Details

This class inherits a constructor from CocinaDisplay::Dates::Date

Class Method Details

.munge_to_yyyy(text) ⇒ Object



582
583
584
585
# File 'lib/cocina_display/dates/date.rb', line 582

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



577
578
579
580
# File 'lib/cocina_display/dates/date.rb', line 577

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