Class: OpenWeatherClient::Weather
- Inherits:
-
Object
- Object
- OpenWeatherClient::Weather
- Defined in:
- lib/open_weather_client/weather.rb
Overview
Request weather information from OpenWeatherMap or the cache
Instance Attribute Summary collapse
-
#lat ⇒ Object
- Float
-
latitude of the requested location.
-
#lon ⇒ Object
- Float
-
longitude of the requested location.
-
#time ⇒ Object
- Time
-
time of the requested weather.
Instance Method Summary collapse
-
#get ⇒ Object
get the weather according to the specified parameters.
-
#initialize(lat:, lon:, time: Time.now) ⇒ Weather
constructor
Initialize a new Weather request.
Constructor Details
#initialize(lat:, lon:, time: Time.now) ⇒ Weather
Initialize a new Weather request
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/open_weather_client/weather.rb', line 22 def initialize(lat:, lon:, time: Time.now) if OpenWeatherClient.configuration.spatial_quantization.respond_to?(:call) lat, lon = OpenWeatherClient.configuration.spatial_quantization.call(lat, lon) end raise RangeError unless (-90..90).member?(lat) raise RangeError unless (-180..180).member?(lon) @lat = lat @lon = lon @time = time end |
Instance Attribute Details
#lat ⇒ Object
- Float
-
latitude of the requested location
8 9 10 |
# File 'lib/open_weather_client/weather.rb', line 8 def lat @lat end |
#lon ⇒ Object
- Float
-
longitude of the requested location
10 11 12 |
# File 'lib/open_weather_client/weather.rb', line 10 def lon @lon end |
#time ⇒ Object
- Time
-
time of the requested weather
12 13 14 |
# File 'lib/open_weather_client/weather.rb', line 12 def time @time end |
Instance Method Details
#get ⇒ Object
get the weather according to the specified parameters
41 42 43 44 45 |
# File 'lib/open_weather_client/weather.rb', line 41 def get OpenWeatherClient.cache.get(lat: lat, lon: lon, time: time) rescue KeyError OpenWeatherClient::Request.get(lat: lat, lon: lon, time: time) end |