Class: WeatherSage::Weather::Point

Inherits:
BaseObject show all
Defined in:
lib/weather-sage/weather/point.rb

Overview

Thin wrapper around lat/long point in weather API.

Instance Attribute Summary collapse

Attributes inherited from BaseObject

#cache

Instance Method Summary collapse

Constructor Details

#initialize(ctx, x, y) ⇒ Point

Create a new Point object at the given longitude x and latitude y.



11
12
13
14
# File 'lib/weather-sage/weather/point.rb', line 11

def initialize(ctx, x, y)
  super(ctx)
  @x, @y = x, y
end

Instance Attribute Details

#xObject (readonly)

Returns the value of attribute x.



5
6
7
# File 'lib/weather-sage/weather/point.rb', line 5

def x
  @x
end

Instance Method Details

#forecastObject

Returns a weather forecast for this point.



42
43
44
# File 'lib/weather-sage/weather/point.rb', line 42

def forecast
  forecast_by_type('forecast')
end

#hourly_forecastObject

Returns an hourly weather forecast for this point.



49
50
51
# File 'lib/weather-sage/weather/point.rb', line 49

def hourly_forecast
  forecast_by_type('forecastHourly')
end

#propertiesObject

Returns a hash of properties for this point.



31
32
33
34
35
36
37
# File 'lib/weather-sage/weather/point.rb', line 31

def properties
  # build request path
  path = 'points/%2.4f%%2C%2.4f' % [@y, @x]

  # execute request, return properties
  get(path)['properties']
end

#stationsObject

Returns a list of weather stations near this point.



19
20
21
22
23
24
25
26
# File 'lib/weather-sage/weather/point.rb', line 19

def stations
  # build request path
  path = 'points/%2.4f%%2C%2.4f/stations' % [@y, @x]

  get(path)['features'].map { |row|
    WeatherSage::Weather::Station.from_json(@ctx, row)
  }
end