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”. URN render: year only (RFC 5141-bis URN spec).

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.

Returns:

  • (Boolean)


17
18
19
# File 'lib/pubid/components/date.rb', line 17

def present?
  !year.nil? && !year.to_s.empty?
end

#render(context: nil) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/pubid/components/date.rb', line 21

def render(context: nil)
  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



31
32
33
34
35
36
37
# File 'lib/pubid/components/date.rb', line 31

def to_s(_context: nil, _include_month: false)
  return year.to_s unless month

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