Class: Ullr::Forecast
- Inherits:
-
Object
- Object
- Ullr::Forecast
- Defined in:
- lib/ullr/forecast.rb
Constant Summary collapse
- NOAA_ENDPOINT =
"http://forecast.weather.gov/MapClick.php?lat={{lat}}&lon={{lon}}&FcstType=dwml"
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#forecast_string ⇒ Object
Returns the value of attribute forecast_string.
-
#lat ⇒ Object
Returns the value of attribute lat.
-
#lon ⇒ Object
Returns the value of attribute lon.
-
#noaa_endpoint ⇒ Object
Returns the value of attribute noaa_endpoint.
-
#socket_error ⇒ Object
Returns the value of attribute socket_error.
Instance Method Summary collapse
- #get_noaa_forecast ⇒ Object
-
#initialize(options = {}) ⇒ Forecast
constructor
A new instance of Forecast.
Constructor Details
#initialize(options = {}) ⇒ Forecast
Returns a new instance of Forecast.
8 9 10 11 12 13 14 15 |
# File 'lib/ullr/forecast.rb', line 8 def initialize(={}) [:lat,:lon].each do |o| raise(ArgumentError, "#{o.to_s} is required!") if ![o] || ![o].instance_of?(Float) end @lat = [:lat] @lon = [:lon] @noaa_endpoint = NOAA_ENDPOINT.gsub("{{lat}}",@lat.to_s).gsub("{{lon}}",@lon.to_s) end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
5 6 7 |
# File 'lib/ullr/forecast.rb', line 5 def data @data end |
#forecast_string ⇒ Object
Returns the value of attribute forecast_string.
5 6 7 |
# File 'lib/ullr/forecast.rb', line 5 def forecast_string @forecast_string end |
#lat ⇒ Object
Returns the value of attribute lat.
5 6 7 |
# File 'lib/ullr/forecast.rb', line 5 def lat @lat end |
#lon ⇒ Object
Returns the value of attribute lon.
5 6 7 |
# File 'lib/ullr/forecast.rb', line 5 def lon @lon end |
#noaa_endpoint ⇒ Object
Returns the value of attribute noaa_endpoint.
5 6 7 |
# File 'lib/ullr/forecast.rb', line 5 def noaa_endpoint @noaa_endpoint end |
#socket_error ⇒ Object
Returns the value of attribute socket_error.
5 6 7 |
# File 'lib/ullr/forecast.rb', line 5 def socket_error @socket_error end |
Instance Method Details
#get_noaa_forecast ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ullr/forecast.rb', line 17 def get_noaa_forecast @socket_error = false @data = [] begin resp = open(@noaa_endpoint) @forecast_string = resp.read rescue SocketError @socket_error = true end if !@socket_error data = Ullr::NOAA::Data.parse(@forecast_string) forecast = data.find{|o| o.type == 'forecast'} if forecast time_layout = forecast.time_layouts.find{|t| t.layout_key =~ /k-p12h/ } time_layout.start_valid_times.each_with_index do |time,i| params = forecast.parameters word = params.worded_forecast.texts[i] point = OpenStruct.new point.start_time = time.period_start point.name = time.period_name point.pop = params.pops.values[i].value point.text = word.value point.snow = word.has_snow? point.high_temperature = word.high_temperature point.low_temperature = word.low_temperature point.wind_direction = word.wind_direction point.wind_speeds = word.wind_speeds point.snow_estimate = word.snow_estimate @data << point end end end return @data end |