Class: SunTimes
- Inherits:
-
Object
- Object
- SunTimes
- Defined in:
- lib/sun_times.rb,
lib/sun_times/version.rb
Defined Under Namespace
Modules: VERSION
Constant Summary collapse
- DEFAULT_ZENITH =
90.83333
- KNOWN_EVENTS =
[:rise, :set]
- DEGREES_PER_HOUR =
360.0 / 24.0
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
-
.calculate(event, date, latitude, longitude, options = {}) ⇒ Object
Deprecated: use SunTimes.new.rise/set(…).
-
.rise(date, latitude, longitude, options = {}) ⇒ Object
Deprecated: use SunTimes.new.rise(…).
-
.set(date, latitude, longitude, options = {}) ⇒ Object
Deprecated: use SunTimes.new.set(…).
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ SunTimes
constructor
-
options
- *:never_rises_result
- the value to be returned if the sun never rises on the supplied date, *:never_sets_result
- the value to be returned if the sun never sets on the supplied date, *:zenith
- default 90.83333.
-
-
#rise(date, latitude, longitude) ⇒ Object
Calculates the sunrise time for a specific date and location.
-
#set(date, latitude, longitude) ⇒ Object
calculates sunset, see #rise for parameters.
Constructor Details
#initialize(options = {}) ⇒ SunTimes
-
options
--
:never_rises_result
- the value to be returned if the sun never rises on the supplied date, -
:never_sets_result
- the value to be returned if the sun never sets on the supplied date, -
:zenith
- default 90.83333
-
54 55 56 57 58 59 60 |
# File 'lib/sun_times.rb', line 54 def initialize( = {}) @options = { :never_sets_result => nil, :never_rises_result => nil, :zenith => DEFAULT_ZENITH, }.merge() end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
33 34 35 |
# File 'lib/sun_times.rb', line 33 def @options end |
Class Method Details
.calculate(event, date, latitude, longitude, options = {}) ⇒ Object
Deprecated: use SunTimes.new.rise/set(…)
46 47 48 |
# File 'lib/sun_times.rb', line 46 def self.calculate(event, date, latitude, longitude, = {}) new().calculate(event, date, latitude, longitude) end |
.rise(date, latitude, longitude, options = {}) ⇒ Object
Deprecated: use SunTimes.new.rise(…)
36 37 38 |
# File 'lib/sun_times.rb', line 36 def self.rise(date, latitude, longitude, = {}) new().calculate(:rise, date, latitude, longitude, ) end |
.set(date, latitude, longitude, options = {}) ⇒ Object
Deprecated: use SunTimes.new.set(…)
41 42 43 |
# File 'lib/sun_times.rb', line 41 def self.set(date, latitude, longitude, = {}) new().calculate(:set, date, latitude, longitude, ) end |
Instance Method Details
#rise(date, latitude, longitude) ⇒ Object
Calculates the sunrise time for a specific date and location
Parameters
-
date
- An object that responds to :to_datetime. -
latitude
- The latitude of the location in degrees. -
longitude
- The longitude of the location in degrees.
Example
SunTimes.new.rise(Date.new(2010, 3, 8), 43.779, 11.432)
> Mon Mar 08 05:39:53 UTC 2010
72 73 74 |
# File 'lib/sun_times.rb', line 72 def rise(date, latitude, longitude) calculate(:rise, date, latitude, longitude) end |
#set(date, latitude, longitude) ⇒ Object
calculates sunset, see #rise for parameters
77 78 79 |
# File 'lib/sun_times.rb', line 77 def set(date, latitude, longitude) calculate(:set, date, latitude, longitude) end |