Class: LunarCalendar::Date
- Inherits:
-
Object
- Object
- LunarCalendar::Date
- Includes:
- Comparable
- Defined in:
- lib/lunar_calendar/date.rb
Overview
The abstract date of calendar
Instance Attribute Summary collapse
- #day ⇒ Object readonly
- #month ⇒ Object readonly
- #year ⇒ Object readonly
Instance Method Summary collapse
-
#<=>(other) ⇒ Number
The compare result.
-
#==(other) ⇒ Boolean
Date is same or not.
-
#binary ⇒ Number
The packed solar date.
-
#initialize(year, month, day) ⇒ Date
constructor
A new instance of Date.
-
#to_i ⇒ Number
The number of days.
Constructor Details
#initialize(year, month, day) ⇒ Date
Returns a new instance of Date.
16 17 18 19 20 |
# File 'lib/lunar_calendar/date.rb', line 16 def initialize(year, month, day) @year = year @month = month @day = day end |
Instance Attribute Details
#day ⇒ Object (readonly)
9 10 11 |
# File 'lib/lunar_calendar/date.rb', line 9 def day @day end |
#month ⇒ Object (readonly)
9 10 11 |
# File 'lib/lunar_calendar/date.rb', line 9 def month @month end |
#year ⇒ Object (readonly)
9 10 11 |
# File 'lib/lunar_calendar/date.rb', line 9 def year @year end |
Instance Method Details
#<=>(other) ⇒ Number
Returns the compare result.
50 51 52 |
# File 'lib/lunar_calendar/date.rb', line 50 def <=>(other) binary <=> other.binary end |
#==(other) ⇒ Boolean
Returns date is same or not.
39 40 41 42 43 44 45 |
# File 'lib/lunar_calendar/date.rb', line 39 def ==(other) return false unless other.is_a?(self.class) @year == other.year && @month == other.month && @day == other.day end |
#binary ⇒ Number
Returns the packed solar date.
32 33 34 |
# File 'lib/lunar_calendar/date.rb', line 32 def binary @binary ||= (@year << 9) | (@month << 5) | @day end |
#to_i ⇒ Number
Returns the number of days.
25 26 27 |
# File 'lib/lunar_calendar/date.rb', line 25 def to_i -1 end |