class EarthTools::Result::SunriseSunset

The sunrise/sunset result.

Public Instance Methods

date() click to toggle source

The date of the sunrise/sunset data as a hash @return [Hash] Hash containing year, month, and day as integers

# File lib/earth_tools/result/sunrise_sunset.rb, line 12
def date
  { :year => Time.now.year, :month => @data['date']['month'].to_i, :day => @data['date']['day'].to_i }
end
evening_astronomical_twilight() click to toggle source

The evening astronomical twilight time @return [Time] the astronomical twilight time for the evening

# File lib/earth_tools/result/sunrise_sunset.rb, line 60
def evening_astronomical_twilight
  create_time @data['evening']['twilight']['astronomical']
end
evening_civil_twilight() click to toggle source

The evening civil twilight time @return [Time] the civil twilight time for the evening

# File lib/earth_tools/result/sunrise_sunset.rb, line 67
def evening_civil_twilight
  create_time @data['evening']['twilight']['civil']
end
evening_nautical_twilight() click to toggle source

The evening nautical twilight time @return [Time] the nautical twilight time for the evening

# File lib/earth_tools/result/sunrise_sunset.rb, line 74
def evening_nautical_twilight
  create_time @data['evening']['twilight']['nautical']
end
evening_twilight(type) click to toggle source

The evening twilight time for the specified type @param [Symbol] the type of evening twilight time @return [Time] the specified evening twilight time

# File lib/earth_tools/result/sunrise_sunset.rb, line 53
def evening_twilight(type)
  twilight :evening, type
end
morning_astronomical_twilight() click to toggle source

The morning astronomical twilight time @return [Time] the astronomical twilight time for the morning

# File lib/earth_tools/result/sunrise_sunset.rb, line 81
def morning_astronomical_twilight
  create_time @data['morning']['twilight']['astronomical']
end
morning_civil_twilight() click to toggle source

The morning civil twilight time @return [Time] the civil twilight time for the morning

# File lib/earth_tools/result/sunrise_sunset.rb, line 88
def morning_civil_twilight
  create_time @data['morning']['twilight']['civil']
end
morning_nautical_twilight() click to toggle source

The morning nautical twilight time @return [Time] the nautical twilight time for the morning

# File lib/earth_tools/result/sunrise_sunset.rb, line 95
def morning_nautical_twilight
  create_time @data['morning']['twilight']['nautical']
end
morning_twilight(type) click to toggle source

The morning twilight time for the specified type @param [Symbol] the type of morning twilight time @return [Time] the specified morning twilight time

# File lib/earth_tools/result/sunrise_sunset.rb, line 45
def morning_twilight(type)
  twilight :morning, type
end
sunrise() click to toggle source

The sunrise time @return [Time] the sunrise time

# File lib/earth_tools/result/sunrise_sunset.rb, line 19
def sunrise
  create_time @data['morning']['sunrise']
end
sunset() click to toggle source

The sunset time @return [Time] the sunset time

# File lib/earth_tools/result/sunrise_sunset.rb, line 26
def sunset
  create_time @data['evening']['sunset']
end
twilight(time, type) click to toggle source

The twilight time for the specified time and type @param [Symbol] the time (:morning or :evening) @param [Symbol] the type (:astronomical, :civil, or :nautical) @return [Time] the requested twilight time

# File lib/earth_tools/result/sunrise_sunset.rb, line 35
def twilight(time, type)
  time = time.to_sym if time.is_a?(String)
  type = type.to_sym if type.is_a?(String)
  send "#{time}_#{type}_twilight" if [:morning, :evening].include?(time) && [:astronomical, :civil, :nautical].include?(type)
end
utc_offset() click to toggle source

The number of hours offset from UTC disregarding any correction for daylight saving time See {en.wikipedia.org/wiki/UTC_offset}. @return [Integer] the UTC offset

# File lib/earth_tools/result/sunrise_sunset.rb, line 103
def utc_offset
  @data['date']['timezone'].to_i
end

Private Instance Methods

create_time(time) click to toggle source

Parses time @returns [Time] The parse time

# File lib/earth_tools/result/sunrise_sunset.rb, line 112
def create_time(time)
  times = time.split(':').collect{|s| s.to_i}
  Time.new(date[:year], date[:month], date[:day], times[0], times[1], times[2], utc_offset * 3600)
end