Class: Pubid::Components::Date
- Inherits:
-
Lutaml::Model::Serializable
- Object
- Lutaml::Model::Serializable
- Pubid::Components::Date
- Defined in:
- lib/pubid/components/date.rb
Overview
Publication date component
Direct Known Subclasses
Instance Method Summary collapse
-
#eql?(other) ⇒ Boolean
Checks equality with another date component.
-
#hash ⇒ Integer
Returns hash code for date component.
-
#render(context: nil) ⇒ String
Render date with optional context for flavor-specific formatting.
- #to_s(_context: nil, _include_month: false) ⇒ Object
Instance Method Details
#eql?(other) ⇒ Boolean
Checks equality with another date component
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 |
#hash ⇒ Integer
Note:
Memoized for performance
Returns hash code for date component
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
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 |