Class: GeoNamesAPI::TimeZone

Inherits:
SingletonEndpoint show all
Defined in:
lib/geonames_api/time_zone.rb

Constant Summary collapse

METHOD =
"timezoneJSON"
FIND_PARAMS =
%w(lat lng radius date)

Instance Attribute Summary

Attributes inherited from Entity

#request_params

Instance Method Summary collapse

Methods inherited from SingletonEndpoint

endpoint_returns_list?

Methods inherited from Base

all, find, where

Methods inherited from Entity

#create_attribute, #initialize, #marshal_dump, #marshal_load, #parse_attr, #parse_response, #set_default_type

Constructor Details

This class inherits a constructor from GeoNamesAPI::Entity

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/geonames_api/time_zone.rb', line 24

def method_missing(method, *args)
  case method
    # Provides the local and utc time variant of each time
    # Examples: time_zone.sunrise_local, time_zone.time_utc
    when /\A(.*)_(local|utc)\Z/
      send($2, $1)
  end
end

Instance Method Details

#common_nameObject



11
12
13
# File 'lib/geonames_api/time_zone.rb', line 11

def common_name
  ActiveSupport::TimeZone::MAPPING.key(timezone_id)
end

#local(time_type) ⇒ Object



15
16
17
18
# File 'lib/geonames_api/time_zone.rb', line 15

def local(time_type)
  t = DateTime.parse(send(time_type))
  time_zone.local(t.year, t.month, t.day, t.hour, t.minute)
end

#time_zoneObject



7
8
9
# File 'lib/geonames_api/time_zone.rb', line 7

def time_zone
  ActiveSupport::TimeZone.new(timezone_id)
end

#utc(time_type) ⇒ Object



20
21
22
# File 'lib/geonames_api/time_zone.rb', line 20

def utc(time_type)
  local(time_type).utc
end