Class: Pubid::Components::Date

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

Overview

Publication date component

Direct Known Subclasses

Bsi::Components::Date

Instance Method Summary collapse

Instance Method Details

#eql?(other) ⇒ Boolean

Checks equality with another date component

Parameters:

  • other (Object)

    object to compare with

Returns:

  • (Boolean)

    true if equal



42
43
44
45
46
# File 'lib/pubid/components/date.rb', line 42

def eql?(other)
  return false unless other.is_a?(self.class)

  year == other.year && month == other.month && day == other.day
end

#hashInteger

Note:

Memoized for performance

Returns hash code for date component

Returns:

  • (Integer)

    hash code



35
36
37
# File 'lib/pubid/components/date.rb', line 35

def hash
  @hash ||= [year, month, day].compact.map(&:hash).hash
end

#render(context: nil) ⇒ String

Render date with optional context for flavor-specific formatting

Parameters:

  • _context (RenderingContext)

    rendering context (for future extensibility)

  • _include_month (Boolean)

    include month in output (for future extensibility)

Returns:

  • (String)

    rendered date string



20
21
22
# File 'lib/pubid/components/date.rb', line 20

def render(context: nil)
  to_s
end

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



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

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

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