Skip to content

Commit

Permalink
Revise atmosphere barometer to reflect tri-state.
Browse files Browse the repository at this point in the history
- revise atmosphere.barometer to reflect tri-state as "steady",
  "rising", or "falling" via one of the new
  YahooWeather::Atmosphere::Barometer constants, whereas previously it
  was simply a boolean for whether rising.  Thanks to Andy Weber for
  suggestion.
  • Loading branch information
Walter Korman committed Dec 9, 2009
1 parent 1ddaf49 commit b328f56
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rdoc
@@ -1,3 +1,9 @@
* [shaper] revise atmosphere.barometer to reflect tri-state as
"steady", "rising", or "falling" via one of the new
YahooWeather::Atmosphere::Barometer constants, whereas previously it
was simply a boolean for whether rising. Thanks to Andy Weber for
suggestion.

= YAHOO_WEATHER_20091021_1_0_1

* [shaper] update documentation to reflect reality and use suffix for
Expand Down
27 changes: 23 additions & 4 deletions lib/yahoo-weather.rb
Expand Up @@ -98,6 +98,17 @@ def initialize (payload)

# Describes the specific atmospheric conditions at a location.
class Atmosphere
# Constants representing the state of the barometric pressure.
#
class Barometer
STEADY = 'steady'
RISING = 'rising'
FALLING = 'falling'

# lists all possible barometer constants
ALL = [ STEADY, RISING, FALLING ]
end

# the humidity of the surroundings.
attr_reader :humidity

Expand All @@ -107,14 +118,22 @@ class Atmosphere
# the pressure level of the surroundings.
attr_reader :pressure

# whether the air currents are rising.
attr_reader :rising

# the state of the barometer, defined as one of the
# YahooWeather::Atmosphere::Barometer constants.
attr_reader :barometer

def initialize (payload)
@humidity = payload['humidity'].to_i
@visibility = payload['visibility'].to_i
@pressure = payload['pressure'].to_f
@rising = (payload['rising'] == "1")

# map barometric pressure direction to appropriate constant
@barometer = nil
case payload['rising'].to_i
when 0: @barometer = Barometer::STEADY
when 1: @barometer = Barometer::RISING
when 2: @barometer = Barometer::FALLING
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/test_api.rb
Expand Up @@ -72,7 +72,7 @@ def _assert_valid_response (response, request_location, units, city, region, cou
assert_kind_of Numeric, response.atmosphere.humidity
assert_kind_of Numeric, response.atmosphere.visibility
assert_kind_of Numeric, response.atmosphere.pressure
assert(response.atmosphere.rising.is_a?(TrueClass) || response.atmosphere.rising.is_a?(FalseClass))
assert(YahooWeather::Atmosphere::Barometer::ALL.include?(response.atmosphere.barometer))

# check the condition info
assert_instance_of YahooWeather::Condition, response.condition
Expand Down

0 comments on commit b328f56

Please sign in to comment.