Class: LunarCalendar::Calculator::Lunar

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

Overview

The Lunar Date Calculator

Instance Method Summary collapse

Constructor Details

#initialize(solar) ⇒ Lunar

Returns a new instance of Lunar.

Parameters:

Since:

  • 0.1.0



14
15
16
17
18
19
20
# File 'lib/lunar_calendar/calculator/lunar.rb', line 14

def initialize(solar)
  @solar = solar
  @lunar_year = LunarYear.new(position)
  @year = position + LunarCalendar::SUPPORT_YEARS.begin
  @month = 1
  @day = 1
end

Instance Method Details

#performLunarCalendar::Lunar

Returns the lunar date.

Returns:

Since:

  • 0.1.0



25
26
27
28
29
30
31
# File 'lib/lunar_calendar/calculator/lunar.rb', line 25

def perform
  move_days

  @month -= 1 if leap?

  LunarCalendar::Lunar.new(@year, @month, @day, leap_month?)
end

#positionNumber

Returns position of table.

Returns:

  • (Number)

    position of table

Since:

  • 0.1.0



36
37
38
39
40
41
42
43
# File 'lib/lunar_calendar/calculator/lunar.rb', line 36

def position
  return @position unless @position.nil?

  index = @solar.year - LunarCalendar::SUPPORT_YEARS.begin
  # If new years in the previous year
  index -= 1 if LunarCalendar::Data::NEW_YEARS[index] > @solar.binary
  @position = index
end