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

Class Method 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.



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

def day
  @day
end

#monthObject (readonly)

Returns the value of attribute month.



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

def month
  @month
end

Class Method Details

.from_date(date) ⇒ Object



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

def self.from_date(date)
  new(date.month, date.day)
end

Instance Method Details

#<=>(other) ⇒ Object



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

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

#concretize(year) ⇒ Object



35
36
37
# File 'lib/calendarium-romanum/abstract_date.rb', line 35

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

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#hashObject



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

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