Class: LunarCalendar::Calculator::Lunar
- Inherits:
-
Object
- Object
- LunarCalendar::Calculator::Lunar
- Defined in:
- lib/lunar_calendar/calculator/lunar.rb
Overview
The Lunar Date Calculator
Instance Method Summary collapse
-
#initialize(solar) ⇒ Lunar
constructor
A new instance of Lunar.
-
#perform ⇒ LunarCalendar::Lunar
The lunar date.
-
#position ⇒ Number
Position of table.
Constructor Details
#initialize(solar) ⇒ Lunar
Returns a new instance of Lunar.
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
#perform ⇒ LunarCalendar::Lunar
Returns the lunar date.
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 |
#position ⇒ Number
Returns position of table.
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 |