Class: Zmanim::AstronomicalCalendar

Inherits:
Object
  • Object
show all
Defined in:
lib/zmanim/astronomical_calendar.rb

Direct Known Subclasses

ZmanimCalendar

Constant Summary collapse

GEOMETRIC_ZENITH =
90
CIVIL_ZENITH =
96
NAUTICAL_ZENITH =
102
ASTRONOMICAL_ZENITH =
108
MINUTE_MILLIS =
60 * 1000
HOUR_MILLIS =
MINUTE_MILLIS * 60

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ AstronomicalCalendar

Returns a new instance of AstronomicalCalendar.



15
16
17
18
19
# File 'lib/zmanim/astronomical_calendar.rb', line 15

def initialize(opts={})
  @geo_location = opts[:geo_location] || Util::GeoLocation.GMT
  @date = opts[:date] || Date.today
  @astronomical_calculator = opts[:calculator] || Util::NOAACalculator.new
end

Instance Attribute Details

#astronomical_calculatorObject

Returns the value of attribute astronomical_calculator.



3
4
5
# File 'lib/zmanim/astronomical_calendar.rb', line 3

def astronomical_calculator
  @astronomical_calculator
end

#dateObject

Returns the value of attribute date.



3
4
5
# File 'lib/zmanim/astronomical_calendar.rb', line 3

def date
  @date
end

#geo_locationObject

Returns the value of attribute geo_location.



3
4
5
# File 'lib/zmanim/astronomical_calendar.rb', line 3

def geo_location
  @geo_location
end

Instance Method Details

#sea_level_sunriseObject



25
26
27
# File 'lib/zmanim/astronomical_calendar.rb', line 25

def sea_level_sunrise
  sunrise_offset_by_degrees(GEOMETRIC_ZENITH)
end

#sea_level_sunsetObject



37
38
39
# File 'lib/zmanim/astronomical_calendar.rb', line 37

def sea_level_sunset
  sunset_offset_by_degrees(GEOMETRIC_ZENITH)
end

#sun_transitObject



67
68
69
70
71
72
73
# File 'lib/zmanim/astronomical_calendar.rb', line 67

def sun_transit
  sunrise = sea_level_sunrise
  sunset = sea_level_sunset
  return unless sunrise && sunset
  noon_hour = (temporal_hour(sunrise, sunset) / HOUR_MILLIS) * 6.0
  sunrise + (noon_hour / 24.0)
end

#sunriseObject



21
22
23
# File 'lib/zmanim/astronomical_calendar.rb', line 21

def sunrise
  date_time_from_time_of_day utc_sunrise(GEOMETRIC_ZENITH), :sunrise
end

#sunrise_offset_by_degrees(offset_zenith) ⇒ Object



29
30
31
# File 'lib/zmanim/astronomical_calendar.rb', line 29

def sunrise_offset_by_degrees(offset_zenith)
  date_time_from_time_of_day utc_sea_level_sunrise(offset_zenith), :sunrise
end

#sunsetObject



33
34
35
# File 'lib/zmanim/astronomical_calendar.rb', line 33

def sunset
  date_time_from_time_of_day utc_sunset(GEOMETRIC_ZENITH), :sunset
end

#sunset_offset_by_degrees(offset_zenith) ⇒ Object



41
42
43
# File 'lib/zmanim/astronomical_calendar.rb', line 41

def sunset_offset_by_degrees(offset_zenith)
  date_time_from_time_of_day utc_sea_level_sunset(offset_zenith), :sunset
end

#temporal_hour(sunrise = sea_level_sunrise, sunset = sea_level_sunset) ⇒ Object



61
62
63
64
65
# File 'lib/zmanim/astronomical_calendar.rb', line 61

def temporal_hour(sunrise=sea_level_sunrise, sunset=sea_level_sunset)
  return unless sunset && sunrise
  daytime_hours = ((sunset - sunrise) * 24).to_f
  (daytime_hours / 12) * HOUR_MILLIS
end

#utc_sea_level_sunrise(zenith) ⇒ Object



53
54
55
# File 'lib/zmanim/astronomical_calendar.rb', line 53

def utc_sea_level_sunrise(zenith)
  astronomical_calculator.utc_sunrise(adjusted_date, geo_location, zenith, adjust_for_elevation: false)
end

#utc_sea_level_sunset(zenith) ⇒ Object



57
58
59
# File 'lib/zmanim/astronomical_calendar.rb', line 57

def utc_sea_level_sunset(zenith)
  astronomical_calculator.utc_sunset(adjusted_date, geo_location, zenith, adjust_for_elevation: false)
end

#utc_sunrise(zenith) ⇒ Object



45
46
47
# File 'lib/zmanim/astronomical_calendar.rb', line 45

def utc_sunrise(zenith)
  astronomical_calculator.utc_sunrise(adjusted_date, geo_location, zenith, adjust_for_elevation: true)
end

#utc_sunset(zenith) ⇒ Object



49
50
51
# File 'lib/zmanim/astronomical_calendar.rb', line 49

def utc_sunset(zenith)
  astronomical_calculator.utc_sunset(adjusted_date, geo_location, zenith, adjust_for_elevation: true)
end