Class: LunarCalendar::LunarYear

Inherits:
Object
  • Object
show all
Defined in:
lib/lunar_calendar/lunar_year.rb

Overview

The leap and months of specify year

Instance Method Summary collapse

Constructor Details

#initialize(offset) ⇒ LunarYear

Returns a new instance of LunarYear.



11
12
13
# File 'lib/lunar_calendar/lunar_year.rb', line 11

def initialize(offset)
  @offset = offset
end

Instance Method Details

#binaryNumber

Returns the packed leap data.

Returns:

  • (Number)

    the packed leap data



16
17
18
# File 'lib/lunar_calendar/lunar_year.rb', line 16

def binary
  @binary ||= LunarCalendar::Data::LEAP_MONTHS[@offset]
end

#leap_monthNumber

Returns the leap month.

Returns:

  • (Number)

    the leap month



28
29
30
# File 'lib/lunar_calendar/lunar_year.rb', line 28

def leap_month
  @leap_month ||= LunarCalendar::Utils.decode(binary, 4, 13)
end

#month_daysArray<Number>

Returns month days.

Returns:

  • (Array<Number>)

    month days



21
22
23
24
25
# File 'lib/lunar_calendar/lunar_year.rb', line 21

def month_days
  (0..12).map do |month|
    LunarCalendar::Utils.decode(binary, 1, 12 - month) == 1 ? 30 : 29
  end
end