Class: CocinaDisplay::Dates::EdtfFormat

Inherits:
Date
  • Object
show all
Defined in:
lib/cocina_display/dates/date.rb

Overview

Strict EDTF parser.

Constant Summary

Constants inherited from Date

Date::BCE_CHAR_SORT_MAP, Date::UNPARSABLE_VALUES

Instance Attribute Summary collapse

Attributes inherited from Date

#cocina, #encoding, #type

Class Method Summary collapse

Methods inherited from Date

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

Constructor Details

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

Instance Attribute Details

#dateObject (readonly)

Returns the value of attribute date.



501
502
503
# File 'lib/cocina_display/dates/date.rb', line 501

def date
  @date
end

Class Method Details

.normalize_to_edtf(value) ⇒ Object



503
504
505
506
507
508
509
510
511
512
513
514
# File 'lib/cocina_display/dates/date.rb', line 503

def self.normalize_to_edtf(value)
  return "0000" if value.strip == "0"

  case value
  when /^\d{1,3}$/
    value.rjust(4, "0") if /^\d{1,3}$/.match?(value)
  when /^-\d{1,3}$/
    "-#{value.sub(/^-/, "").rjust(4, "0")}"
  else
    value
  end
end