Class: CalendariumRomanum::AbstractDate

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/calendarium-romanum/abstract_date.rb

Overview

a date not bound to a particular year

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(month, day) ⇒ AbstractDate

Returns a new instance of AbstractDate.



7
8
9
10
11
# File 'lib/calendarium-romanum/abstract_date.rb', line 7

def initialize(month, day)
  validate! month, day
  @month = month
  @day = day
end

Instance Attribute Details

#dayObject (readonly)

Returns the value of attribute day.



13
14
15
# File 'lib/calendarium-romanum/abstract_date.rb', line 13

def day
  @day
end

#monthObject (readonly)

Returns the value of attribute month.



13
14
15
# File 'lib/calendarium-romanum/abstract_date.rb', line 13

def month
  @month
end

Instance Method Details

#<=>(other) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/calendarium-romanum/abstract_date.rb', line 15

def <=>(other)
  if month != other.month
    month <=> other.month
  else
    day <=> other.day
  end
end

#concretize(year) ⇒ Object



31
32
33
# File 'lib/calendarium-romanum/abstract_date.rb', line 31

def concretize(year)
  Date.new(year, month, day)
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/calendarium-romanum/abstract_date.rb', line 27

def eql?(other)
  month == other.month && day == other.day
end

#hashObject



23
24
25
# File 'lib/calendarium-romanum/abstract_date.rb', line 23

def hash
  (month * 100 + day).hash
end