Class: Pubid::Components::Date

Inherits:
Lutaml::Model::Serializable
  • Object
show all
Defined in:
lib/pubid/components/date.rb

Overview

Publication date component

Human render: "YYYY" or "YYYY-MM" or "YYYY-MM-DD"; or "--" when the date slot is present but explicitly undated (ISO/IEC undated-reference convention, e.g. "ISO 16634:--"). URN render: year only (RFC 5141-bis URN spec); flavors that drop the slot when undated gate that decision at the URN-generator level, not here.

Direct Known Subclasses

Bsi::Components::Date

Instance Method Summary collapse

Instance Method Details

#present?Boolean

True when the year is set to a non-empty value, OR the date is explicitly marked undated. An undated date is a meaningful publication-date slot (it is what renders as :-- in ISO/IEC), so callers that gate rendering on "is there a date at all?" should treat undated as present.

Returns:

  • (Boolean)


25
26
27
28
# File 'lib/pubid/components/date.rb', line 25

def present?
  return true if undated
  !year.nil? && !year.to_s.empty?
end

#render(context: nil) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/pubid/components/date.rb', line 34

def render(context: nil)
  return "--" if undated? && (year.nil? || year.to_s.empty?)
  return nil unless present?
  return year.to_s if context&.urn?
  return year.to_s unless month

  result = "#{year}-#{pad2(month)}"
  result += "-#{pad2(day)}" if day
  result
end

#to_s(_context: nil, _include_month: false) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/pubid/components/date.rb', line 45

def to_s(_context: nil, _include_month: false)
  return "--" if undated? && (year.nil? || year.to_s.empty?)
  return year.to_s unless month

  result = "#{year}-#{pad2(month)}"
  result += "-#{pad2(day)}" if day
  result
end

#undated?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/pubid/components/date.rb', line 30

def undated?
  !!undated
end