Class: LunarCalendar::Date

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/lunar_calendar/date.rb

Overview

The abstract date of calendar

Direct Known Subclasses

Lunar, Solar

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(year, month, day) ⇒ Date

Returns a new instance of Date.

Parameters:

  • year (Number)

    year

  • month (Number)

    month

  • day (Number)

    day

Since:

  • 0.1.0



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

#dayObject (readonly)

Since:

  • 0.1.0



9
10
11
# File 'lib/lunar_calendar/date.rb', line 9

def day
  @day
end

#monthObject (readonly)

Since:

  • 0.1.0



9
10
11
# File 'lib/lunar_calendar/date.rb', line 9

def month
  @month
end

#yearObject (readonly)

Since:

  • 0.1.0



9
10
11
# File 'lib/lunar_calendar/date.rb', line 9

def year
  @year
end

Instance Method Details

#<=>(other) ⇒ Number

Returns the compare result.

Returns:

  • (Number)

    the compare result

Since:

  • 0.1.0



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.

Returns:

  • (Boolean)

    date is same or not

Since:

  • 0.1.0



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

#binaryNumber

Returns the packed solar date.

Returns:

  • (Number)

    the packed solar date

Since:

  • 0.1.0



32
33
34
# File 'lib/lunar_calendar/date.rb', line 32

def binary
  @binary ||= (@year << 9) | (@month << 5) | @day
end

#to_iNumber

Returns the number of days.

Returns:

  • (Number)

    the number of days

Since:

  • 0.1.0



25
26
27
# File 'lib/lunar_calendar/date.rb', line 25

def to_i
  -1
end