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.

Parameters:

  • month (Fixnum)
  • day (Fixnum)

Raises:

  • (RangeError)

    on invalid month/day value


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

#dayObject (readonly)

Returns the value of attribute day


25
26
27
# File 'lib/calendarium-romanum/abstract_date.rb', line 25

def day
  @day
end

#monthObject (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).

Parameters:

  • date (Date)

Returns:


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

Produce a Date by providing a year to an AbstractDate

Parameters:

  • year (Fixnum)

Returns:

  • (Date)

47
48
49
# File 'lib/calendarium-romanum/abstract_date.rb', line 47

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

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)

39
40
41
# File 'lib/calendarium-romanum/abstract_date.rb', line 39

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

#hashObject


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

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