Class: Astronoby::Events::MoonPhases

Inherits:
Object
  • Object
show all
Defined in:
lib/astronoby/events/moon_phases.rb

Constant Summary collapse

BASE_YEAR =
2000

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(year, month, phase, phase_increment) ⇒ MoonPhases

Returns a new instance of MoonPhases.

Parameters:

  • year (Integer)

    Requested year

  • month (Integer)

    Requested month

  • phase (Symbol)

    Moon phase

  • phase_increment (Float)

    Phase increment



37
38
39
40
41
42
# File 'lib/astronoby/events/moon_phases.rb', line 37

def initialize(year, month, phase, phase_increment)
  @year = year
  @month = month
  @phase = phase
  @phase_increment = phase_increment
end

Class Method Details

.phases_for(year:, month:) ⇒ Array<Astronoby::MoonPhase>

Returns List of Moon phases.

Parameters:

  • year (Integer)

    Requested year

  • month (Integer)

    Requested month

Returns:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/astronoby/events/moon_phases.rb', line 17

def self.phases_for(year:, month:)
  Astronoby.cache.fetch([:moon_phases, year, month]) do
    [
      MoonPhase.first_quarter(new(year, month, :first_quarter, -0.75).time),
      MoonPhase.full_moon(new(year, month, :full_moon, -0.5).time),
      MoonPhase.last_quarter(new(year, month, :last_quarter, -0.25).time),
      MoonPhase.new_moon(new(year, month, :new_moon, 0).time),
      MoonPhase.first_quarter(new(year, month, :first_quarter, 0.25).time),
      MoonPhase.full_moon(new(year, month, :full_moon, 0.5).time),
      MoonPhase.last_quarter(new(year, month, :last_quarter, 0.75).time),
      MoonPhase.new_moon(new(year, month, :new_moon, 1).time),
      MoonPhase.first_quarter(new(year, month, :first_quarter, 1.25).time)
    ].select { _1.time.month == month }
  end
end

Instance Method Details

#timeTime

Returns Time of the Moon phase.

Returns:

  • (Time)

    Time of the Moon phase



45
46
47
48
49
50
51
52
53
54
# File 'lib/astronoby/events/moon_phases.rb', line 45

def time
  correction = moon_phases_periodic_terms
    .public_send(:"#{@phase}_correction")
  terrestrial_time = Instant.from_terrestrial_time(
    julian_ephemeris_day +
      correction +
      moon_phases_periodic_terms.additional_corrections
  )
  terrestrial_time.to_time.round
end