class WeatherSage::Weather::Point

Thin wrapper around lat/long point in weather API.

Attributes

x[RW]

Public Class Methods

new(ctx, x, y) click to toggle source

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

Calls superclass method WeatherSage::Weather::BaseObject::new
# File lib/weather-sage/weather/point.rb, line 11
def initialize(ctx, x, y)
  super(ctx)
  @x, @y = x, y
end

Public Instance Methods

forecast() click to toggle source

Returns a weather forecast for this point.

# File lib/weather-sage/weather/point.rb, line 42
def forecast
  forecast_by_type('forecast')
end
hourly_forecast() click to toggle source

Returns an hourly weather forecast for this point.

# File lib/weather-sage/weather/point.rb, line 49
def hourly_forecast
  forecast_by_type('forecastHourly')
end
properties() click to toggle source

Returns a hash of properties for this point.

# 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
stations() click to toggle source

Returns a list of weather stations near this point.

# 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

Private Instance Methods

forecast_by_type(forecast_type) click to toggle source

Get forecast type from properties.

Remove the scheme, host, and leading slash from the URL provided in the properties.

# File lib/weather-sage/weather/point.rb, line 61
def forecast_by_type(forecast_type)
  # parse URI for given request type
  uri = URI.parse(properties[forecast_type])

  # strip scheme, host, and leading slash from URI to build path
  path = uri.path.gsub(/^\//, '')

  # request forecast and build a Forecast object from it
  ::WeatherSage::Weather::Forecast.new(@ctx, get(path))
end