Class: SunTimes

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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 = {})
  @options = {
    :never_sets_result  => nil,
    :never_rises_result => nil,
    :zenith             => DEFAULT_ZENITH,
  }.merge(options)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @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, options = {})
  new(options).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, options = {})
  new(options).calculate(:rise, date, latitude, longitude, options)
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, options = {})
  new(options).calculate(:set, date, latitude, longitude, options)
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