class Forecast::IO::Cache::Store
Public Class Methods
new(config = Cache.configuration)
click to toggle source
# File lib/forecast_io/cache/store.rb, line 9 def initialize config = Cache.configuration @config = config @backend = PGAdaptor.new('forecasts', ForecastData) end
Public Instance Methods
fetch(lat, lon, time)
click to toggle source
# File lib/forecast_io/cache/store.rb, line 14 def fetch lat, lon, time @backend.fetch Sequel.lit(<<-SQL), time >= :start AND time <= :end AND earth_box( ll_to_earth(:lat, :lon), :radius ) @> ll_to_earth( latitude, longitude ) SQL start: time - offset, end: time + offset, lat: lat, lon: lon, radius: radius end
store(forecast)
click to toggle source
# File lib/forecast_io/cache/store.rb, line 30 def store forecast @backend.insert forecast forecast end
Private Instance Methods
offset()
click to toggle source
# File lib/forecast_io/cache/store.rb, line 42 def offset @config.timeframe * 60 end
radius()
click to toggle source
# File lib/forecast_io/cache/store.rb, line 37 def radius # nm to m @config.radius * 1852 end