Class: NOAA::CurrentConditions

Inherits:
Object
  • Object
show all
Defined in:
lib/noaa/current_conditions.rb

Overview

Representation of the current conditions for a given observation point.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(doc) ⇒ CurrentConditions

:notnew:



15
16
17
# File 'lib/noaa/current_conditions.rb', line 15

def initialize(doc) #:notnew:
  @doc = doc
end

Class Method Details

.from_xml(doc) ⇒ Object

:nodoc:



10
11
12
# File 'lib/noaa/current_conditions.rb', line 10

def from_xml(doc) #:nodoc:
  new(doc)
end

Instance Method Details

#dew_point(unit = :f) ⇒ Object

The current dew point.

conditions.dew_point           #=> dew point in fahrenheit
conditions.dew_point(:c)       #=> dew point in celsius
conditions.dew_point(:kelvin)  #=> anything else raises an exception


141
142
143
# File 'lib/noaa/current_conditions.rb', line 141

def dew_point(unit = :f)
  text_from_node_with_unit('dewpoint', unit, :f, :c).to_i
end

#heat_index(unit = :f) ⇒ Object

The current heat index

conditions.heat_index           #=> heat index in fahrenheit
conditions.heat_index(:c)       #=> heat index in celsius
conditions.heat_index(:kelvin)  #=> anything else raises an exception


152
153
154
# File 'lib/noaa/current_conditions.rb', line 152

def heat_index(unit = :f)
  text_from_node_with_unit('heat_index', unit, :f, :c).to_i
end

#image_urlObject

Return the NWS image URL for the current weather as string



73
74
75
# File 'lib/noaa/current_conditions.rb', line 73

def image_url
  @image_url ||= "#{text_from_node('icon_url_base')}#{text_from_node('icon_url_name')}"
end

#observed_atObject

Time object containing the time at which these conditions were observed at the NOAA station



22
23
24
# File 'lib/noaa/current_conditions.rb', line 22

def observed_at
  @observed_at ||= Time.parse(text_from_node('observation_time_rfc822'))
end

#pressure(unit = :in) ⇒ Object

The current barometric pressure

conditions.pressure       #=> pressure in inches
conditions.pressure(:mb)  #=> pressure in millibars
conditions.pressure(:psi) #=> anything else raises an exception


130
131
132
# File 'lib/noaa/current_conditions.rb', line 130

def pressure(unit = :in)
  text_from_node_with_unit('pressure', unit, :in, :mb).to_f
end

#relative_humidityObject

The current relative humidity percentage (0-100)



91
92
93
# File 'lib/noaa/current_conditions.rb', line 91

def relative_humidity
  text_from_node('relative_humidity').to_i
end

#temperature(unit = :f) ⇒ Object

The current temperature in the requested units.

conditions.temperature           #=> temperature in fahrenheit
conditions.temperature(:c)       #=> temperature in celsius
conditions.temperature(:kelvin)  #=> anything else raises an exception


84
85
86
# File 'lib/noaa/current_conditions.rb', line 84

def temperature(unit = :f)
  text_from_node_with_unit('temp', unit, :f, :c).to_i
end

#visibilityObject

The current visibility in miles



170
171
172
# File 'lib/noaa/current_conditions.rb', line 170

def visibility
  text_from_node('visibility_mi').to_f
end

#weather_descriptionObject Also known as: weather_summary

Text description of the current weather conditions, e.g. “Fair”



29
30
31
# File 'lib/noaa/current_conditions.rb', line 29

def weather_description
  @weather_description ||= text_from_node('weather')
end

#weather_type_codeObject

NWS code representing weather type. This distills the #weather_description into one of a much more manageable set of possibilities. Possible values are:

  • :skc - Clear

  • :wind - Windy

  • :few - A Few Clouds

  • :sct - Partly Cloudy

  • :bkn - Mostly Cloudy

  • :ovc - Overcast

  • :ra1 - Light Rain

  • :ra - Rain

  • :shra - Rain Showers

  • :tsra - Thunderstorms

  • :ip - Hail

  • :fzra - Freezing Rain

  • :mix - Wintry Mix

  • :sn - Snow

  • :fg - Fog

  • :smoke - Smoke

  • :dust - Dust/Sand

  • :mist - Haze

  • :svrtsra - Tornado

  • :fzrara - Freezing Rain/Rain

  • :raip - Rain/Hail

  • :rasn - Rain/Snow

  • :hi_shwrs - Showers in Vicinity

  • :hi_tsra - Thunderstorm in Vicinity

See www.weather.gov/xml/current_obs/weather.php for the NWS’s list of possible descriptions and their type codes.



66
67
68
# File 'lib/noaa/current_conditions.rb', line 66

def weather_type_code
  @weather_type_code ||= text_from_node('icon_url_name').gsub(/^n|\.jpg$/, '').to_sym
end

#wind_chill(unit = :f) ⇒ Object

The current wind chill

conditions.wind_chill           #=> wind chill in fahrenheit
conditions.wind_chill(:c)       #=> wind chill in celsius
conditions.wind_chill(:kelvin)  #=> anything else raises an exception


163
164
165
# File 'lib/noaa/current_conditions.rb', line 163

def wind_chill(unit = :f)
  text_from_node_with_unit('windchill', unit, :f, :c).to_i
end

#wind_degreesObject

The current direction that the wind is coming from degrees (e.g. 330)



105
106
107
# File 'lib/noaa/current_conditions.rb', line 105

def wind_degrees
  text_from_node('wind_degrees').to_i
end

#wind_directionObject

The current cardinal or ordinal direction that the wind is coming from (e.g., “Northwest”)



98
99
100
# File 'lib/noaa/current_conditions.rb', line 98

def wind_direction
  text_from_node('wind_dir')
end

#wind_gustObject

The current wind gust in miles per hour as a float, or nil if none



119
120
121
# File 'lib/noaa/current_conditions.rb', line 119

def wind_gust
  text_from_node('wind_gust_mph').to_f
end

#wind_speedObject

The current wind speed in miles per hour as a float (e.g., 3.45)



112
113
114
# File 'lib/noaa/current_conditions.rb', line 112

def wind_speed
  text_from_node('wind_mph').to_f
end