Class: CalendariumRomanum::AbstractDate
- Inherits:
-
Object
- Object
- CalendariumRomanum::AbstractDate
- Includes:
- Comparable
- Defined in:
- lib/calendarium-romanum/abstract_date.rb
Overview
a date not bound to a particular year
Instance Attribute Summary collapse
-
#day ⇒ Object
readonly
Returns the value of attribute day.
-
#month ⇒ Object
readonly
Returns the value of attribute month.
Class Method Summary collapse
-
.from_date(date) ⇒ AbstractDate
Build a new instance from a
Date
(or an object with similar public interface).
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#concretize(year) ⇒ Date
(also: #in_year)
Produce a
Date
by providing a year to anAbstractDate
. - #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(month, day) ⇒ AbstractDate
constructor
A new instance of AbstractDate.
Constructor Details
#initialize(month, day) ⇒ AbstractDate
Returns a new instance of AbstractDate.
10 11 12 13 14 |
# File 'lib/calendarium-romanum/abstract_date.rb', line 10 def initialize(month, day) validate! month, day @month = month @day = day end |
Instance Attribute Details
#day ⇒ Object (readonly)
Returns the value of attribute day.
25 26 27 |
# File 'lib/calendarium-romanum/abstract_date.rb', line 25 def day @day end |
#month ⇒ Object (readonly)
Returns the value of attribute month.
25 26 27 |
# File 'lib/calendarium-romanum/abstract_date.rb', line 25 def month @month end |
Class Method Details
.from_date(date) ⇒ AbstractDate
Build a new instance from a Date
(or an object with similar public interface).
21 22 23 |
# File 'lib/calendarium-romanum/abstract_date.rb', line 21 def self.from_date(date) new(date.month, date.day) end |
Instance Method Details
#<=>(other) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/calendarium-romanum/abstract_date.rb', line 27 def <=>(other) if month != other.month month <=> other.month else day <=> other.day end end |
#concretize(year) ⇒ Date Also known as: in_year
Produce a Date
by providing a year to an AbstractDate
47 48 49 |
# File 'lib/calendarium-romanum/abstract_date.rb', line 47 def concretize(year) Date.new(year, month, day) end |
#eql?(other) ⇒ Boolean
39 40 41 |
# File 'lib/calendarium-romanum/abstract_date.rb', line 39 def eql?(other) month == other.month && day == other.day end |
#hash ⇒ Object
35 36 37 |
# File 'lib/calendarium-romanum/abstract_date.rb', line 35 def hash (month * 100 + day).hash end |