class CalendariumRomanum::AbstractDate
a date not bound to a particular year
Attributes
day[R]
month[R]
Public Class Methods
from_date(date)
click to toggle source
Build a new instance from a Date
(or an object with similar public interface).
@param date [Date] @return [AbstractDate]
# File lib/calendarium-romanum/abstract_date.rb, line 21 def self.from_date(date) new(date.month, date.day) end
new(month, day)
click to toggle source
@param month [Integer] @param day [Integer] @raise [RangeError] on invalid month
/day
value
# File lib/calendarium-romanum/abstract_date.rb, line 10 def initialize(month, day) validate! month, day @month = month @day = day end
Public Instance Methods
<=>(other)
click to toggle source
# 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)
click to toggle source
Produce a Date
by providing a year to an AbstractDate
@param year [Integer] @return [Date]
# File lib/calendarium-romanum/abstract_date.rb, line 47 def concretize(year) Date.new(year, month, day) end
Also aliased as: in_year
eql?(other)
click to toggle source
# File lib/calendarium-romanum/abstract_date.rb, line 39 def eql?(other) month == other.month && day == other.day end
hash()
click to toggle source
# File lib/calendarium-romanum/abstract_date.rb, line 35 def hash (month * 100 + day).hash end
Private Instance Methods
validate!(month, day)
click to toggle source
# File lib/calendarium-romanum/abstract_date.rb, line 56 def validate!(month, day) unless month >= 1 && month <= 12 raise RangeError.new("Invalid month #{month}.") end day_lte = case month when 2 29 when 1, 3, 5, 7, 8, 10, 12 31 else 30 end unless day > 0 && day <= 31 raise RangeError.new("Invalid day #{day}.") end unless day <= day_lte raise RangeError.new("Invalid day #{day} for month #{month}.") end end