Class: Astronoby::Events::TwilightEvents
- Inherits:
-
Object
- Object
- Astronoby::Events::TwilightEvents
- Defined in:
- lib/astronoby/events/twilight_events.rb
Constant Summary collapse
- TWILIGHTS =
[ CIVIL = :civil, NAUTICAL = :nautical, ASTRONOMICAL = :astronomical ].freeze
- TWILIGHT_ANGLES =
{ CIVIL => Angle.from_degrees(96), NAUTICAL => Angle.from_degrees(102), ASTRONOMICAL => Angle.from_degrees(108) }.freeze
- PERIODS_OF_THE_DAY =
[ MORNING = :morning, EVENING = :evening ].freeze
Instance Attribute Summary collapse
-
#evening_astronomical_twilight_time ⇒ Object
readonly
Returns the value of attribute evening_astronomical_twilight_time.
-
#evening_civil_twilight_time ⇒ Object
readonly
Returns the value of attribute evening_civil_twilight_time.
-
#evening_nautical_twilight_time ⇒ Object
readonly
Returns the value of attribute evening_nautical_twilight_time.
-
#morning_astronomical_twilight_time ⇒ Object
readonly
Returns the value of attribute morning_astronomical_twilight_time.
-
#morning_civil_twilight_time ⇒ Object
readonly
Returns the value of attribute morning_civil_twilight_time.
-
#morning_nautical_twilight_time ⇒ Object
readonly
Returns the value of attribute morning_nautical_twilight_time.
Instance Method Summary collapse
-
#initialize(observer:, sun:) ⇒ TwilightEvents
constructor
A new instance of TwilightEvents.
- #time_for_zenith_angle(period_of_the_day:, zenith_angle:) ⇒ Object
Constructor Details
#initialize(observer:, sun:) ⇒ TwilightEvents
Returns a new instance of TwilightEvents.
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/astronoby/events/twilight_events.rb', line 30 def initialize(observer:, sun:) @observer = observer @sun = sun PERIODS_OF_THE_DAY.each do |period_of_the_day| TWILIGHT_ANGLES.each do |twilight, _| zenith_angle = TWILIGHT_ANGLES[twilight] instance_variable_set( :"@#{period_of_the_day}_#{twilight}_twilight_time", compute(period_of_the_day, zenith_angle) ) end end end |
Instance Attribute Details
#evening_astronomical_twilight_time ⇒ Object (readonly)
Returns the value of attribute evening_astronomical_twilight_time.
23 24 25 |
# File 'lib/astronoby/events/twilight_events.rb', line 23 def evening_astronomical_twilight_time @evening_astronomical_twilight_time end |
#evening_civil_twilight_time ⇒ Object (readonly)
Returns the value of attribute evening_civil_twilight_time.
23 24 25 |
# File 'lib/astronoby/events/twilight_events.rb', line 23 def evening_civil_twilight_time @evening_civil_twilight_time end |
#evening_nautical_twilight_time ⇒ Object (readonly)
Returns the value of attribute evening_nautical_twilight_time.
23 24 25 |
# File 'lib/astronoby/events/twilight_events.rb', line 23 def evening_nautical_twilight_time @evening_nautical_twilight_time end |
#morning_astronomical_twilight_time ⇒ Object (readonly)
Returns the value of attribute morning_astronomical_twilight_time.
23 24 25 |
# File 'lib/astronoby/events/twilight_events.rb', line 23 def morning_astronomical_twilight_time @morning_astronomical_twilight_time end |
#morning_civil_twilight_time ⇒ Object (readonly)
Returns the value of attribute morning_civil_twilight_time.
23 24 25 |
# File 'lib/astronoby/events/twilight_events.rb', line 23 def morning_civil_twilight_time @morning_civil_twilight_time end |
#morning_nautical_twilight_time ⇒ Object (readonly)
Returns the value of attribute morning_nautical_twilight_time.
23 24 25 |
# File 'lib/astronoby/events/twilight_events.rb', line 23 def morning_nautical_twilight_time @morning_nautical_twilight_time end |
Instance Method Details
#time_for_zenith_angle(period_of_the_day:, zenith_angle:) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/astronoby/events/twilight_events.rb', line 46 def time_for_zenith_angle(period_of_the_day:, zenith_angle:) unless PERIODS_OF_THE_DAY.include?(period_of_the_day) raise IncompatibleArgumentsError, "Only #{PERIODS_OF_THE_DAY.join(" or ")} are allowed as period_of_the_day, got #{period_of_the_day}" end compute(period_of_the_day, zenith_angle) end |