attack-barometer 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +20 -0
 - data/README.rdoc +266 -0
 - data/VERSION.yml +4 -0
 - data/bin/barometer +63 -0
 - data/lib/barometer/base.rb +52 -0
 - data/lib/barometer/data/current.rb +93 -0
 - data/lib/barometer/data/distance.rb +131 -0
 - data/lib/barometer/data/forecast.rb +66 -0
 - data/lib/barometer/data/geo.rb +98 -0
 - data/lib/barometer/data/location.rb +20 -0
 - data/lib/barometer/data/measurement.rb +161 -0
 - data/lib/barometer/data/pressure.rb +133 -0
 - data/lib/barometer/data/speed.rb +147 -0
 - data/lib/barometer/data/sun.rb +35 -0
 - data/lib/barometer/data/temperature.rb +164 -0
 - data/lib/barometer/data/units.rb +55 -0
 - data/lib/barometer/data/zone.rb +124 -0
 - data/lib/barometer/data.rb +15 -0
 - data/lib/barometer/extensions/graticule.rb +50 -0
 - data/lib/barometer/extensions/httparty.rb +21 -0
 - data/lib/barometer/query.rb +228 -0
 - data/lib/barometer/services/google.rb +146 -0
 - data/lib/barometer/services/noaa.rb +6 -0
 - data/lib/barometer/services/service.rb +324 -0
 - data/lib/barometer/services/weather_bug.rb +6 -0
 - data/lib/barometer/services/weather_dot_com.rb +6 -0
 - data/lib/barometer/services/wunderground.rb +285 -0
 - data/lib/barometer/services/yahoo.rb +274 -0
 - data/lib/barometer/services.rb +6 -0
 - data/lib/barometer/weather.rb +187 -0
 - data/lib/barometer.rb +52 -0
 - data/spec/barometer_spec.rb +162 -0
 - data/spec/data_current_spec.rb +225 -0
 - data/spec/data_distance_spec.rb +336 -0
 - data/spec/data_forecast_spec.rb +150 -0
 - data/spec/data_geo_spec.rb +90 -0
 - data/spec/data_location_spec.rb +59 -0
 - data/spec/data_measurement_spec.rb +411 -0
 - data/spec/data_pressure_spec.rb +336 -0
 - data/spec/data_speed_spec.rb +374 -0
 - data/spec/data_sun_spec.rb +76 -0
 - data/spec/data_temperature_spec.rb +396 -0
 - data/spec/data_zone_spec.rb +133 -0
 - data/spec/fixtures/current_calgary_ab.xml +1 -0
 - data/spec/fixtures/forecast_calgary_ab.xml +1 -0
 - data/spec/fixtures/geocode_40_73.xml +1 -0
 - data/spec/fixtures/geocode_90210.xml +1 -0
 - data/spec/fixtures/geocode_T5B4M9.xml +1 -0
 - data/spec/fixtures/geocode_calgary_ab.xml +1 -0
 - data/spec/fixtures/geocode_newyork_ny.xml +1 -0
 - data/spec/fixtures/google_calgary_ab.xml +1 -0
 - data/spec/fixtures/yahoo_90210.xml +1 -0
 - data/spec/query_spec.rb +469 -0
 - data/spec/service_google_spec.rb +144 -0
 - data/spec/service_wunderground_spec.rb +330 -0
 - data/spec/service_yahoo_spec.rb +299 -0
 - data/spec/services_spec.rb +1106 -0
 - data/spec/spec_helper.rb +14 -0
 - data/spec/units_spec.rb +101 -0
 - data/spec/weather_spec.rb +265 -0
 - metadata +119 -0
 
| 
         @@ -0,0 +1,330 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'spec_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            describe "Wunderground" do
         
     | 
| 
      
 4 
     | 
    
         
            +
              
         
     | 
| 
      
 5 
     | 
    
         
            +
              before(:each) do
         
     | 
| 
      
 6 
     | 
    
         
            +
                @accepted_formats = [:zipcode, :postalcode, :coordinates, :geocode]
         
     | 
| 
      
 7 
     | 
    
         
            +
                @base_uri = "http://api.wunderground.com/auto/wui/geo"
         
     | 
| 
      
 8 
     | 
    
         
            +
              end
         
     | 
| 
      
 9 
     | 
    
         
            +
              
         
     | 
| 
      
 10 
     | 
    
         
            +
              describe "the class methods" do
         
     | 
| 
      
 11 
     | 
    
         
            +
                
         
     | 
| 
      
 12 
     | 
    
         
            +
                it "defines accepted_formats" do
         
     | 
| 
      
 13 
     | 
    
         
            +
                  Barometer::Wunderground.accepted_formats.should == @accepted_formats
         
     | 
| 
      
 14 
     | 
    
         
            +
                end
         
     | 
| 
      
 15 
     | 
    
         
            +
                
         
     | 
| 
      
 16 
     | 
    
         
            +
                it "defines get_current" do
         
     | 
| 
      
 17 
     | 
    
         
            +
                  Barometer::Wunderground.respond_to?("get_current").should be_true
         
     | 
| 
      
 18 
     | 
    
         
            +
                end
         
     | 
| 
      
 19 
     | 
    
         
            +
                
         
     | 
| 
      
 20 
     | 
    
         
            +
                it "defines get_forecast" do
         
     | 
| 
      
 21 
     | 
    
         
            +
                  Barometer::Wunderground.respond_to?("get_forecast").should be_true
         
     | 
| 
      
 22 
     | 
    
         
            +
                end
         
     | 
| 
      
 23 
     | 
    
         
            +
                
         
     | 
| 
      
 24 
     | 
    
         
            +
              end
         
     | 
| 
      
 25 
     | 
    
         
            +
              
         
     | 
| 
      
 26 
     | 
    
         
            +
              describe "building the current data" do
         
     | 
| 
      
 27 
     | 
    
         
            +
                
         
     | 
| 
      
 28 
     | 
    
         
            +
                it "defines the build method" do
         
     | 
| 
      
 29 
     | 
    
         
            +
                  Barometer::Wunderground.respond_to?("build_current").should be_true
         
     | 
| 
      
 30 
     | 
    
         
            +
                end
         
     | 
| 
      
 31 
     | 
    
         
            +
                
         
     | 
| 
      
 32 
     | 
    
         
            +
                it "requires Hash input" do
         
     | 
| 
      
 33 
     | 
    
         
            +
                  lambda { Barometer::Wunderground.build_current }.should raise_error(ArgumentError)
         
     | 
| 
      
 34 
     | 
    
         
            +
                  lambda { Barometer::Wunderground.build_current({}) }.should_not raise_error(ArgumentError)
         
     | 
| 
      
 35 
     | 
    
         
            +
                end
         
     | 
| 
      
 36 
     | 
    
         
            +
                
         
     | 
| 
      
 37 
     | 
    
         
            +
                it "returns Barometer::CurrentMeasurement object" do
         
     | 
| 
      
 38 
     | 
    
         
            +
                  current = Barometer::Wunderground.build_current({})
         
     | 
| 
      
 39 
     | 
    
         
            +
                  current.is_a?(Barometer::CurrentMeasurement).should be_true
         
     | 
| 
      
 40 
     | 
    
         
            +
                end
         
     | 
| 
      
 41 
     | 
    
         
            +
                
         
     | 
| 
      
 42 
     | 
    
         
            +
              end
         
     | 
| 
      
 43 
     | 
    
         
            +
              
         
     | 
| 
      
 44 
     | 
    
         
            +
              describe "building the forecast data" do
         
     | 
| 
      
 45 
     | 
    
         
            +
                
         
     | 
| 
      
 46 
     | 
    
         
            +
                it "defines the build method" do
         
     | 
| 
      
 47 
     | 
    
         
            +
                  Barometer::Wunderground.respond_to?("build_forecast").should be_true
         
     | 
| 
      
 48 
     | 
    
         
            +
                end
         
     | 
| 
      
 49 
     | 
    
         
            +
                
         
     | 
| 
      
 50 
     | 
    
         
            +
                it "requires Hash input" do
         
     | 
| 
      
 51 
     | 
    
         
            +
                  lambda { Barometer::Wunderground.build_forecast }.should raise_error(ArgumentError)
         
     | 
| 
      
 52 
     | 
    
         
            +
                  lambda { Barometer::Wunderground.build_forecast({}) }.should_not raise_error(ArgumentError)
         
     | 
| 
      
 53 
     | 
    
         
            +
                end
         
     | 
| 
      
 54 
     | 
    
         
            +
                
         
     | 
| 
      
 55 
     | 
    
         
            +
                it "returns Array object" do
         
     | 
| 
      
 56 
     | 
    
         
            +
                  current = Barometer::Wunderground.build_forecast({})
         
     | 
| 
      
 57 
     | 
    
         
            +
                  current.is_a?(Array).should be_true
         
     | 
| 
      
 58 
     | 
    
         
            +
                end
         
     | 
| 
      
 59 
     | 
    
         
            +
                
         
     | 
| 
      
 60 
     | 
    
         
            +
              end
         
     | 
| 
      
 61 
     | 
    
         
            +
              
         
     | 
| 
      
 62 
     | 
    
         
            +
              describe "building the station data" do
         
     | 
| 
      
 63 
     | 
    
         
            +
                
         
     | 
| 
      
 64 
     | 
    
         
            +
                it "defines the build method" do
         
     | 
| 
      
 65 
     | 
    
         
            +
                  Barometer::Wunderground.respond_to?("build_station").should be_true
         
     | 
| 
      
 66 
     | 
    
         
            +
                end
         
     | 
| 
      
 67 
     | 
    
         
            +
                
         
     | 
| 
      
 68 
     | 
    
         
            +
                it "requires Hash input" do
         
     | 
| 
      
 69 
     | 
    
         
            +
                  lambda { Barometer::Wunderground.build_station }.should raise_error(ArgumentError)
         
     | 
| 
      
 70 
     | 
    
         
            +
                  lambda { Barometer::Wunderground.build_station({}) }.should_not raise_error(ArgumentError)
         
     | 
| 
      
 71 
     | 
    
         
            +
                end
         
     | 
| 
      
 72 
     | 
    
         
            +
                
         
     | 
| 
      
 73 
     | 
    
         
            +
                it "returns Barometer::Location object" do
         
     | 
| 
      
 74 
     | 
    
         
            +
                  station = Barometer::Wunderground.build_station({})
         
     | 
| 
      
 75 
     | 
    
         
            +
                  station.is_a?(Barometer::Location).should be_true
         
     | 
| 
      
 76 
     | 
    
         
            +
                end
         
     | 
| 
      
 77 
     | 
    
         
            +
                
         
     | 
| 
      
 78 
     | 
    
         
            +
              end
         
     | 
| 
      
 79 
     | 
    
         
            +
              
         
     | 
| 
      
 80 
     | 
    
         
            +
              describe "building the location data" do
         
     | 
| 
      
 81 
     | 
    
         
            +
                
         
     | 
| 
      
 82 
     | 
    
         
            +
                it "defines the build method" do
         
     | 
| 
      
 83 
     | 
    
         
            +
                  Barometer::Wunderground.respond_to?("build_location").should be_true
         
     | 
| 
      
 84 
     | 
    
         
            +
                end
         
     | 
| 
      
 85 
     | 
    
         
            +
                
         
     | 
| 
      
 86 
     | 
    
         
            +
                it "requires Hash input" do
         
     | 
| 
      
 87 
     | 
    
         
            +
                  lambda { Barometer::Wunderground.build_location }.should raise_error(ArgumentError)
         
     | 
| 
      
 88 
     | 
    
         
            +
                  lambda { Barometer::Wunderground.build_location({}) }.should_not raise_error(ArgumentError)
         
     | 
| 
      
 89 
     | 
    
         
            +
                end
         
     | 
| 
      
 90 
     | 
    
         
            +
                
         
     | 
| 
      
 91 
     | 
    
         
            +
                it "returns Barometer::Location object" do
         
     | 
| 
      
 92 
     | 
    
         
            +
                  location = Barometer::Wunderground.build_location({})
         
     | 
| 
      
 93 
     | 
    
         
            +
                  location.is_a?(Barometer::Location).should be_true
         
     | 
| 
      
 94 
     | 
    
         
            +
                end
         
     | 
| 
      
 95 
     | 
    
         
            +
                
         
     | 
| 
      
 96 
     | 
    
         
            +
              end
         
     | 
| 
      
 97 
     | 
    
         
            +
              
         
     | 
| 
      
 98 
     | 
    
         
            +
              describe "building the timezone" do
         
     | 
| 
      
 99 
     | 
    
         
            +
                
         
     | 
| 
      
 100 
     | 
    
         
            +
                it "defines the build method" do
         
     | 
| 
      
 101 
     | 
    
         
            +
                  Barometer::Wunderground.respond_to?("build_timezone").should be_true
         
     | 
| 
      
 102 
     | 
    
         
            +
                end
         
     | 
| 
      
 103 
     | 
    
         
            +
                
         
     | 
| 
      
 104 
     | 
    
         
            +
                it "requires Hash input" do
         
     | 
| 
      
 105 
     | 
    
         
            +
                  lambda { Barometer::Wunderground.build_timezone }.should raise_error(ArgumentError)
         
     | 
| 
      
 106 
     | 
    
         
            +
                  lambda { Barometer::Wunderground.build_timezone({}) }.should_not raise_error(ArgumentError)
         
     | 
| 
      
 107 
     | 
    
         
            +
                end
         
     | 
| 
      
 108 
     | 
    
         
            +
                
         
     | 
| 
      
 109 
     | 
    
         
            +
              end
         
     | 
| 
      
 110 
     | 
    
         
            +
              
         
     | 
| 
      
 111 
     | 
    
         
            +
              describe "building the sun data" do
         
     | 
| 
      
 112 
     | 
    
         
            +
                   
         
     | 
| 
      
 113 
     | 
    
         
            +
                before(:each) do
         
     | 
| 
      
 114 
     | 
    
         
            +
                  @zone = Barometer::Zone.new("Europe/Paris")
         
     | 
| 
      
 115 
     | 
    
         
            +
                end
         
     | 
| 
      
 116 
     | 
    
         
            +
             
     | 
| 
      
 117 
     | 
    
         
            +
                it "defines the build method" do
         
     | 
| 
      
 118 
     | 
    
         
            +
                  Barometer::Wunderground.respond_to?("build_sun").should be_true
         
     | 
| 
      
 119 
     | 
    
         
            +
                end
         
     | 
| 
      
 120 
     | 
    
         
            +
                
         
     | 
| 
      
 121 
     | 
    
         
            +
                it "requires Hash input" do
         
     | 
| 
      
 122 
     | 
    
         
            +
                  lambda { Barometer::Wunderground.build_sun }.should raise_error(ArgumentError)
         
     | 
| 
      
 123 
     | 
    
         
            +
                  lambda { Barometer::Wunderground.build_sun({},@zone) }.should_not raise_error(ArgumentError)
         
     | 
| 
      
 124 
     | 
    
         
            +
                end
         
     | 
| 
      
 125 
     | 
    
         
            +
                
         
     | 
| 
      
 126 
     | 
    
         
            +
                it "requires Barometer::Zone input" do
         
     | 
| 
      
 127 
     | 
    
         
            +
                  lambda { Barometer::Wunderground.build_sun({}) }.should raise_error(ArgumentError)
         
     | 
| 
      
 128 
     | 
    
         
            +
                  lambda { Barometer::Wunderground.build_sun({}, "invalid") }.should raise_error(ArgumentError)
         
     | 
| 
      
 129 
     | 
    
         
            +
                  lambda { Barometer::Wunderground.build_sun({},@zone) }.should_not raise_error(ArgumentError)
         
     | 
| 
      
 130 
     | 
    
         
            +
                end
         
     | 
| 
      
 131 
     | 
    
         
            +
                
         
     | 
| 
      
 132 
     | 
    
         
            +
                it "returns Barometer::Sun object" do
         
     | 
| 
      
 133 
     | 
    
         
            +
                  sun = Barometer::Wunderground.build_sun({},@zone)
         
     | 
| 
      
 134 
     | 
    
         
            +
                  sun.is_a?(Barometer::Sun).should be_true
         
     | 
| 
      
 135 
     | 
    
         
            +
                end
         
     | 
| 
      
 136 
     | 
    
         
            +
                
         
     | 
| 
      
 137 
     | 
    
         
            +
              end
         
     | 
| 
      
 138 
     | 
    
         
            +
              
         
     | 
| 
      
 139 
     | 
    
         
            +
              describe "when measuring" do
         
     | 
| 
      
 140 
     | 
    
         
            +
             
     | 
| 
      
 141 
     | 
    
         
            +
                before(:each) do
         
     | 
| 
      
 142 
     | 
    
         
            +
                  @query = Barometer::Query.new("Calgary,AB")
         
     | 
| 
      
 143 
     | 
    
         
            +
                  @query.preferred = "Calgary,AB"
         
     | 
| 
      
 144 
     | 
    
         
            +
                  @measurement = Barometer::Measurement.new
         
     | 
| 
      
 145 
     | 
    
         
            +
                  
         
     | 
| 
      
 146 
     | 
    
         
            +
                  FakeWeb.register_uri(:get, 
         
     | 
| 
      
 147 
     | 
    
         
            +
                    "http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query=#{CGI.escape(@query.preferred)}",
         
     | 
| 
      
 148 
     | 
    
         
            +
                    :string => File.read(File.join(File.dirname(__FILE__), 
         
     | 
| 
      
 149 
     | 
    
         
            +
                      'fixtures', 
         
     | 
| 
      
 150 
     | 
    
         
            +
                      'current_calgary_ab.xml')
         
     | 
| 
      
 151 
     | 
    
         
            +
                    )
         
     | 
| 
      
 152 
     | 
    
         
            +
                  )  
         
     | 
| 
      
 153 
     | 
    
         
            +
                  FakeWeb.register_uri(:get, 
         
     | 
| 
      
 154 
     | 
    
         
            +
                    "http://api.wunderground.com/auto/wui/geo/ForecastXML/index.xml?query=#{CGI.escape(@query.preferred)}",
         
     | 
| 
      
 155 
     | 
    
         
            +
                    :string => File.read(File.join(File.dirname(__FILE__), 
         
     | 
| 
      
 156 
     | 
    
         
            +
                      'fixtures', 
         
     | 
| 
      
 157 
     | 
    
         
            +
                      'forecast_calgary_ab.xml')
         
     | 
| 
      
 158 
     | 
    
         
            +
                    )
         
     | 
| 
      
 159 
     | 
    
         
            +
                  )
         
     | 
| 
      
 160 
     | 
    
         
            +
                end
         
     | 
| 
      
 161 
     | 
    
         
            +
                
         
     | 
| 
      
 162 
     | 
    
         
            +
                describe "all" do
         
     | 
| 
      
 163 
     | 
    
         
            +
                  
         
     | 
| 
      
 164 
     | 
    
         
            +
                  it "responds to _measure" do
         
     | 
| 
      
 165 
     | 
    
         
            +
                    Barometer::Wunderground.respond_to?("_measure").should be_true
         
     | 
| 
      
 166 
     | 
    
         
            +
                  end
         
     | 
| 
      
 167 
     | 
    
         
            +
                  
         
     | 
| 
      
 168 
     | 
    
         
            +
                  it "requires a Barometer::Measurement object" do
         
     | 
| 
      
 169 
     | 
    
         
            +
                    lambda { Barometer::Wunderground._measure(nil, @query) }.should raise_error(ArgumentError)
         
     | 
| 
      
 170 
     | 
    
         
            +
                    lambda { Barometer::Wunderground._measure("invlaid", @query) }.should raise_error(ArgumentError)
         
     | 
| 
      
 171 
     | 
    
         
            +
             
     | 
| 
      
 172 
     | 
    
         
            +
                    lambda { Barometer::Wunderground._measure(@measurement, @query) }.should_not raise_error(ArgumentError)
         
     | 
| 
      
 173 
     | 
    
         
            +
                  end
         
     | 
| 
      
 174 
     | 
    
         
            +
             
     | 
| 
      
 175 
     | 
    
         
            +
                  it "requires a Barometer::Query query" do
         
     | 
| 
      
 176 
     | 
    
         
            +
                    lambda { Barometer::Wunderground._measure }.should raise_error(ArgumentError)
         
     | 
| 
      
 177 
     | 
    
         
            +
                    lambda { Barometer::Wunderground._measure(@measurement, 1) }.should raise_error(ArgumentError)
         
     | 
| 
      
 178 
     | 
    
         
            +
                    
         
     | 
| 
      
 179 
     | 
    
         
            +
                    lambda { Barometer::Wunderground._measure(@measurement, @query) }.should_not raise_error(ArgumentError)
         
     | 
| 
      
 180 
     | 
    
         
            +
                  end
         
     | 
| 
      
 181 
     | 
    
         
            +
                  
         
     | 
| 
      
 182 
     | 
    
         
            +
                  it "returns a Barometer::Measurement object" do
         
     | 
| 
      
 183 
     | 
    
         
            +
                    result = Barometer::Wunderground._measure(@measurement, @query)
         
     | 
| 
      
 184 
     | 
    
         
            +
                    result.is_a?(Barometer::Measurement).should be_true
         
     | 
| 
      
 185 
     | 
    
         
            +
                    result.current.is_a?(Barometer::CurrentMeasurement).should be_true
         
     | 
| 
      
 186 
     | 
    
         
            +
                    result.forecast.is_a?(Array).should be_true
         
     | 
| 
      
 187 
     | 
    
         
            +
                    
         
     | 
| 
      
 188 
     | 
    
         
            +
                    result.source.should == :wunderground
         
     | 
| 
      
 189 
     | 
    
         
            +
                  end
         
     | 
| 
      
 190 
     | 
    
         
            +
                  
         
     | 
| 
      
 191 
     | 
    
         
            +
                end
         
     | 
| 
      
 192 
     | 
    
         
            +
             
     | 
| 
      
 193 
     | 
    
         
            +
              end
         
     | 
| 
      
 194 
     | 
    
         
            +
              
         
     | 
| 
      
 195 
     | 
    
         
            +
              describe "when answering the simple questions," do
         
     | 
| 
      
 196 
     | 
    
         
            +
                
         
     | 
| 
      
 197 
     | 
    
         
            +
                before(:each) do
         
     | 
| 
      
 198 
     | 
    
         
            +
                  @measurement = Barometer::Measurement.new
         
     | 
| 
      
 199 
     | 
    
         
            +
                end
         
     | 
| 
      
 200 
     | 
    
         
            +
                
         
     | 
| 
      
 201 
     | 
    
         
            +
                describe "currently_wet_by_icon?" do
         
     | 
| 
      
 202 
     | 
    
         
            +
                  
         
     | 
| 
      
 203 
     | 
    
         
            +
                  before(:each) do
         
     | 
| 
      
 204 
     | 
    
         
            +
                    @measurement.current = Barometer::CurrentMeasurement.new
         
     | 
| 
      
 205 
     | 
    
         
            +
                  end
         
     | 
| 
      
 206 
     | 
    
         
            +
             
     | 
| 
      
 207 
     | 
    
         
            +
                  it "returns true if matching icon code" do
         
     | 
| 
      
 208 
     | 
    
         
            +
                    @measurement.current.icon = "rain"
         
     | 
| 
      
 209 
     | 
    
         
            +
                    @measurement.current.icon?.should be_true
         
     | 
| 
      
 210 
     | 
    
         
            +
                    Barometer::Wunderground.currently_wet_by_icon?(@measurement.current).should be_true
         
     | 
| 
      
 211 
     | 
    
         
            +
                  end
         
     | 
| 
      
 212 
     | 
    
         
            +
                  
         
     | 
| 
      
 213 
     | 
    
         
            +
                  it "returns false if NO matching icon code" do
         
     | 
| 
      
 214 
     | 
    
         
            +
                    @measurement.current.icon = "sunny"
         
     | 
| 
      
 215 
     | 
    
         
            +
                    @measurement.current.icon?.should be_true
         
     | 
| 
      
 216 
     | 
    
         
            +
                    Barometer::Wunderground.currently_wet_by_icon?(@measurement.current).should be_false
         
     | 
| 
      
 217 
     | 
    
         
            +
                  end
         
     | 
| 
      
 218 
     | 
    
         
            +
                  
         
     | 
| 
      
 219 
     | 
    
         
            +
                end
         
     | 
| 
      
 220 
     | 
    
         
            +
                
         
     | 
| 
      
 221 
     | 
    
         
            +
                describe "forecasted_wet_by_icon?" do
         
     | 
| 
      
 222 
     | 
    
         
            +
                  
         
     | 
| 
      
 223 
     | 
    
         
            +
                  before(:each) do
         
     | 
| 
      
 224 
     | 
    
         
            +
                    @measurement.forecast = [Barometer::ForecastMeasurement.new]
         
     | 
| 
      
 225 
     | 
    
         
            +
                    @measurement.forecast.first.date = Date.today
         
     | 
| 
      
 226 
     | 
    
         
            +
                    @measurement.forecast.size.should == 1
         
     | 
| 
      
 227 
     | 
    
         
            +
                  end
         
     | 
| 
      
 228 
     | 
    
         
            +
             
     | 
| 
      
 229 
     | 
    
         
            +
                  it "returns true if matching icon code" do
         
     | 
| 
      
 230 
     | 
    
         
            +
                    @measurement.forecast.first.icon = "rain"
         
     | 
| 
      
 231 
     | 
    
         
            +
                    @measurement.forecast.first.icon?.should be_true
         
     | 
| 
      
 232 
     | 
    
         
            +
                    Barometer::Wunderground.forecasted_wet_by_icon?(@measurement.forecast.first).should be_true
         
     | 
| 
      
 233 
     | 
    
         
            +
                  end
         
     | 
| 
      
 234 
     | 
    
         
            +
                  
         
     | 
| 
      
 235 
     | 
    
         
            +
                  it "returns false if NO matching icon code" do
         
     | 
| 
      
 236 
     | 
    
         
            +
                    @measurement.forecast.first.icon = "sunny"
         
     | 
| 
      
 237 
     | 
    
         
            +
                    @measurement.forecast.first.icon?.should be_true
         
     | 
| 
      
 238 
     | 
    
         
            +
                    Barometer::Wunderground.forecasted_wet_by_icon?(@measurement.forecast.first).should be_false
         
     | 
| 
      
 239 
     | 
    
         
            +
                  end
         
     | 
| 
      
 240 
     | 
    
         
            +
                  
         
     | 
| 
      
 241 
     | 
    
         
            +
                end
         
     | 
| 
      
 242 
     | 
    
         
            +
                
         
     | 
| 
      
 243 
     | 
    
         
            +
                describe "currently_sunny_by_icon?" do
         
     | 
| 
      
 244 
     | 
    
         
            +
                  
         
     | 
| 
      
 245 
     | 
    
         
            +
                  before(:each) do
         
     | 
| 
      
 246 
     | 
    
         
            +
                    @measurement.current = Barometer::CurrentMeasurement.new
         
     | 
| 
      
 247 
     | 
    
         
            +
                  end
         
     | 
| 
      
 248 
     | 
    
         
            +
             
     | 
| 
      
 249 
     | 
    
         
            +
                  it "returns true if matching icon code" do
         
     | 
| 
      
 250 
     | 
    
         
            +
                    @measurement.current.icon = "sunny"
         
     | 
| 
      
 251 
     | 
    
         
            +
                    @measurement.current.icon?.should be_true
         
     | 
| 
      
 252 
     | 
    
         
            +
                    Barometer::Wunderground.currently_sunny_by_icon?(@measurement.current).should be_true
         
     | 
| 
      
 253 
     | 
    
         
            +
                  end
         
     | 
| 
      
 254 
     | 
    
         
            +
                  
         
     | 
| 
      
 255 
     | 
    
         
            +
                  it "returns false if NO matching icon code" do
         
     | 
| 
      
 256 
     | 
    
         
            +
                    @measurement.current.icon = "rain"
         
     | 
| 
      
 257 
     | 
    
         
            +
                    @measurement.current.icon?.should be_true
         
     | 
| 
      
 258 
     | 
    
         
            +
                    Barometer::Wunderground.currently_sunny_by_icon?(@measurement.current).should be_false
         
     | 
| 
      
 259 
     | 
    
         
            +
                  end
         
     | 
| 
      
 260 
     | 
    
         
            +
                  
         
     | 
| 
      
 261 
     | 
    
         
            +
                end
         
     | 
| 
      
 262 
     | 
    
         
            +
                
         
     | 
| 
      
 263 
     | 
    
         
            +
                describe "forecasted_sunny_by_icon?" do
         
     | 
| 
      
 264 
     | 
    
         
            +
                  
         
     | 
| 
      
 265 
     | 
    
         
            +
                  before(:each) do
         
     | 
| 
      
 266 
     | 
    
         
            +
                    @measurement.forecast = [Barometer::ForecastMeasurement.new]
         
     | 
| 
      
 267 
     | 
    
         
            +
                    @measurement.forecast.first.date = Date.today
         
     | 
| 
      
 268 
     | 
    
         
            +
                    @measurement.forecast.size.should == 1
         
     | 
| 
      
 269 
     | 
    
         
            +
                  end
         
     | 
| 
      
 270 
     | 
    
         
            +
             
     | 
| 
      
 271 
     | 
    
         
            +
                  it "returns true if matching icon code" do
         
     | 
| 
      
 272 
     | 
    
         
            +
                    @measurement.forecast.first.icon = "sunny"
         
     | 
| 
      
 273 
     | 
    
         
            +
                    @measurement.forecast.first.icon?.should be_true
         
     | 
| 
      
 274 
     | 
    
         
            +
                    Barometer::Wunderground.forecasted_sunny_by_icon?(@measurement.forecast.first).should be_true
         
     | 
| 
      
 275 
     | 
    
         
            +
                  end
         
     | 
| 
      
 276 
     | 
    
         
            +
                  
         
     | 
| 
      
 277 
     | 
    
         
            +
                  it "returns false if NO matching icon code" do
         
     | 
| 
      
 278 
     | 
    
         
            +
                    @measurement.forecast.first.icon = "rain"
         
     | 
| 
      
 279 
     | 
    
         
            +
                    @measurement.forecast.first.icon?.should be_true
         
     | 
| 
      
 280 
     | 
    
         
            +
                    Barometer::Wunderground.forecasted_sunny_by_icon?(@measurement.forecast.first).should be_false
         
     | 
| 
      
 281 
     | 
    
         
            +
                  end
         
     | 
| 
      
 282 
     | 
    
         
            +
                  
         
     | 
| 
      
 283 
     | 
    
         
            +
                end
         
     | 
| 
      
 284 
     | 
    
         
            +
                
         
     | 
| 
      
 285 
     | 
    
         
            +
              end
         
     | 
| 
      
 286 
     | 
    
         
            +
              
         
     | 
| 
      
 287 
     | 
    
         
            +
              describe "overall data correctness" do
         
     | 
| 
      
 288 
     | 
    
         
            +
                
         
     | 
| 
      
 289 
     | 
    
         
            +
                before(:each) do
         
     | 
| 
      
 290 
     | 
    
         
            +
                  @query = Barometer::Query.new("Calgary,AB")
         
     | 
| 
      
 291 
     | 
    
         
            +
                  @query.preferred = "Calgary,AB"
         
     | 
| 
      
 292 
     | 
    
         
            +
                  @measurement = Barometer::Measurement.new
         
     | 
| 
      
 293 
     | 
    
         
            +
                  
         
     | 
| 
      
 294 
     | 
    
         
            +
                  FakeWeb.register_uri(:get, 
         
     | 
| 
      
 295 
     | 
    
         
            +
                    "http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query=#{CGI.escape(@query.preferred)}",
         
     | 
| 
      
 296 
     | 
    
         
            +
                    :string => File.read(File.join(File.dirname(__FILE__), 
         
     | 
| 
      
 297 
     | 
    
         
            +
                      'fixtures', 
         
     | 
| 
      
 298 
     | 
    
         
            +
                      'current_calgary_ab.xml')
         
     | 
| 
      
 299 
     | 
    
         
            +
                    )
         
     | 
| 
      
 300 
     | 
    
         
            +
                  )  
         
     | 
| 
      
 301 
     | 
    
         
            +
                  FakeWeb.register_uri(:get, 
         
     | 
| 
      
 302 
     | 
    
         
            +
                    "http://api.wunderground.com/auto/wui/geo/ForecastXML/index.xml?query=#{CGI.escape(@query.preferred)}",
         
     | 
| 
      
 303 
     | 
    
         
            +
                    :string => File.read(File.join(File.dirname(__FILE__), 
         
     | 
| 
      
 304 
     | 
    
         
            +
                      'fixtures', 
         
     | 
| 
      
 305 
     | 
    
         
            +
                      'forecast_calgary_ab.xml')
         
     | 
| 
      
 306 
     | 
    
         
            +
                    )
         
     | 
| 
      
 307 
     | 
    
         
            +
                  )
         
     | 
| 
      
 308 
     | 
    
         
            +
                end
         
     | 
| 
      
 309 
     | 
    
         
            +
             
     | 
| 
      
 310 
     | 
    
         
            +
               # TODO: complete this
         
     | 
| 
      
 311 
     | 
    
         
            +
               it "should correctly build the data" do
         
     | 
| 
      
 312 
     | 
    
         
            +
                  result = Barometer::Wunderground._measure(@measurement, @query)
         
     | 
| 
      
 313 
     | 
    
         
            +
                  
         
     | 
| 
      
 314 
     | 
    
         
            +
                  # build timezone
         
     | 
| 
      
 315 
     | 
    
         
            +
                  @measurement.timezone.timezone.should == "America/Edmonton"
         
     | 
| 
      
 316 
     | 
    
         
            +
                  
         
     | 
| 
      
 317 
     | 
    
         
            +
                  time = Time.local(2009, 4, 23, 18, 00, 0)
         
     | 
| 
      
 318 
     | 
    
         
            +
                  rise = Time.local(time.year, time.month, time.day, 6, 23)
         
     | 
| 
      
 319 
     | 
    
         
            +
                  set = Time.local(time.year, time.month, time.day, 20, 45)
         
     | 
| 
      
 320 
     | 
    
         
            +
                  sun_rise = @measurement.timezone.tz.local_to_utc(rise)
         
     | 
| 
      
 321 
     | 
    
         
            +
                  sun_set = @measurement.timezone.tz.local_to_utc(set)
         
     | 
| 
      
 322 
     | 
    
         
            +
                  
         
     | 
| 
      
 323 
     | 
    
         
            +
                  # build current
         
     | 
| 
      
 324 
     | 
    
         
            +
                  @measurement.current.sun.rise.should == sun_rise
         
     | 
| 
      
 325 
     | 
    
         
            +
                  @measurement.current.sun.set.should == sun_set
         
     | 
| 
      
 326 
     | 
    
         
            +
                end
         
     | 
| 
      
 327 
     | 
    
         
            +
                
         
     | 
| 
      
 328 
     | 
    
         
            +
              end
         
     | 
| 
      
 329 
     | 
    
         
            +
              
         
     | 
| 
      
 330 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,299 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'spec_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            describe "Yahoo" do
         
     | 
| 
      
 4 
     | 
    
         
            +
              
         
     | 
| 
      
 5 
     | 
    
         
            +
              before(:each) do
         
     | 
| 
      
 6 
     | 
    
         
            +
                @accepted_formats = [:zipcode]
         
     | 
| 
      
 7 
     | 
    
         
            +
                #@base_uri = "http://google.com"
         
     | 
| 
      
 8 
     | 
    
         
            +
              end
         
     | 
| 
      
 9 
     | 
    
         
            +
              
         
     | 
| 
      
 10 
     | 
    
         
            +
              describe "the class methods" do
         
     | 
| 
      
 11 
     | 
    
         
            +
                
         
     | 
| 
      
 12 
     | 
    
         
            +
                it "defines accepted_formats" do
         
     | 
| 
      
 13 
     | 
    
         
            +
                  Barometer::Yahoo.accepted_formats.should == @accepted_formats
         
     | 
| 
      
 14 
     | 
    
         
            +
                end
         
     | 
| 
      
 15 
     | 
    
         
            +
                
         
     | 
| 
      
 16 
     | 
    
         
            +
                # it "defines base_uri" do
         
     | 
| 
      
 17 
     | 
    
         
            +
                #   Barometer::Google.base_uri.should == @base_uri
         
     | 
| 
      
 18 
     | 
    
         
            +
                # end
         
     | 
| 
      
 19 
     | 
    
         
            +
                
         
     | 
| 
      
 20 
     | 
    
         
            +
                it "defines get_all" do
         
     | 
| 
      
 21 
     | 
    
         
            +
                  Barometer::Yahoo.respond_to?("get_all").should be_true
         
     | 
| 
      
 22 
     | 
    
         
            +
                end
         
     | 
| 
      
 23 
     | 
    
         
            +
                
         
     | 
| 
      
 24 
     | 
    
         
            +
              end
         
     | 
| 
      
 25 
     | 
    
         
            +
              
         
     | 
| 
      
 26 
     | 
    
         
            +
              describe "building the current data" do
         
     | 
| 
      
 27 
     | 
    
         
            +
                
         
     | 
| 
      
 28 
     | 
    
         
            +
                it "defines the build method" do
         
     | 
| 
      
 29 
     | 
    
         
            +
                  Barometer::Yahoo.respond_to?("build_current").should be_true
         
     | 
| 
      
 30 
     | 
    
         
            +
                end
         
     | 
| 
      
 31 
     | 
    
         
            +
                
         
     | 
| 
      
 32 
     | 
    
         
            +
                it "requires Hash input" do
         
     | 
| 
      
 33 
     | 
    
         
            +
                  lambda { Barometer::Yahoo.build_current }.should raise_error(ArgumentError)
         
     | 
| 
      
 34 
     | 
    
         
            +
                  lambda { Barometer::Yahoo.build_current({}) }.should_not raise_error(ArgumentError)
         
     | 
| 
      
 35 
     | 
    
         
            +
                end
         
     | 
| 
      
 36 
     | 
    
         
            +
                
         
     | 
| 
      
 37 
     | 
    
         
            +
                it "returns Barometer::CurrentMeasurement object" do
         
     | 
| 
      
 38 
     | 
    
         
            +
                  current = Barometer::Yahoo.build_current({})
         
     | 
| 
      
 39 
     | 
    
         
            +
                  current.is_a?(Barometer::CurrentMeasurement).should be_true
         
     | 
| 
      
 40 
     | 
    
         
            +
                end
         
     | 
| 
      
 41 
     | 
    
         
            +
                
         
     | 
| 
      
 42 
     | 
    
         
            +
              end
         
     | 
| 
      
 43 
     | 
    
         
            +
              
         
     | 
| 
      
 44 
     | 
    
         
            +
              describe "building the forecast data" do
         
     | 
| 
      
 45 
     | 
    
         
            +
                
         
     | 
| 
      
 46 
     | 
    
         
            +
                it "defines the build method" do
         
     | 
| 
      
 47 
     | 
    
         
            +
                  Barometer::Yahoo.respond_to?("build_forecast").should be_true
         
     | 
| 
      
 48 
     | 
    
         
            +
                end
         
     | 
| 
      
 49 
     | 
    
         
            +
                
         
     | 
| 
      
 50 
     | 
    
         
            +
                it "requires Hash input" do
         
     | 
| 
      
 51 
     | 
    
         
            +
                  lambda { Barometer::Yahoo.build_forecast }.should raise_error(ArgumentError)
         
     | 
| 
      
 52 
     | 
    
         
            +
                  lambda { Barometer::Yahoo.build_forecast({}) }.should_not raise_error(ArgumentError)
         
     | 
| 
      
 53 
     | 
    
         
            +
                end
         
     | 
| 
      
 54 
     | 
    
         
            +
                
         
     | 
| 
      
 55 
     | 
    
         
            +
                it "returns Array object" do
         
     | 
| 
      
 56 
     | 
    
         
            +
                  current = Barometer::Yahoo.build_forecast({})
         
     | 
| 
      
 57 
     | 
    
         
            +
                  current.is_a?(Array).should be_true
         
     | 
| 
      
 58 
     | 
    
         
            +
                end
         
     | 
| 
      
 59 
     | 
    
         
            +
                
         
     | 
| 
      
 60 
     | 
    
         
            +
              end
         
     | 
| 
      
 61 
     | 
    
         
            +
              
         
     | 
| 
      
 62 
     | 
    
         
            +
              describe "building the location data" do
         
     | 
| 
      
 63 
     | 
    
         
            +
                
         
     | 
| 
      
 64 
     | 
    
         
            +
                it "defines the build method" do
         
     | 
| 
      
 65 
     | 
    
         
            +
                  Barometer::Yahoo.respond_to?("build_location").should be_true
         
     | 
| 
      
 66 
     | 
    
         
            +
                end
         
     | 
| 
      
 67 
     | 
    
         
            +
                
         
     | 
| 
      
 68 
     | 
    
         
            +
                it "requires Hash input" do
         
     | 
| 
      
 69 
     | 
    
         
            +
                  lambda { Barometer::Yahoo.build_location }.should raise_error(ArgumentError)
         
     | 
| 
      
 70 
     | 
    
         
            +
                  lambda { Barometer::Yahoo.build_location({}) }.should_not raise_error(ArgumentError)
         
     | 
| 
      
 71 
     | 
    
         
            +
                end
         
     | 
| 
      
 72 
     | 
    
         
            +
                
         
     | 
| 
      
 73 
     | 
    
         
            +
                it "requires Barometer::Geo input" do
         
     | 
| 
      
 74 
     | 
    
         
            +
                  geo = Barometer::Geo.new({})
         
     | 
| 
      
 75 
     | 
    
         
            +
                  lambda { Barometer::Yahoo.build_location({}, {}) }.should raise_error(ArgumentError)
         
     | 
| 
      
 76 
     | 
    
         
            +
                  lambda { Barometer::Yahoo.build_location({}, geo) }.should_not raise_error(ArgumentError)
         
     | 
| 
      
 77 
     | 
    
         
            +
                end
         
     | 
| 
      
 78 
     | 
    
         
            +
                
         
     | 
| 
      
 79 
     | 
    
         
            +
                it "returns Barometer::Location object" do
         
     | 
| 
      
 80 
     | 
    
         
            +
                  location = Barometer::Yahoo.build_location({})
         
     | 
| 
      
 81 
     | 
    
         
            +
                  location.is_a?(Barometer::Location).should be_true
         
     | 
| 
      
 82 
     | 
    
         
            +
                end
         
     | 
| 
      
 83 
     | 
    
         
            +
                
         
     | 
| 
      
 84 
     | 
    
         
            +
              end
         
     | 
| 
      
 85 
     | 
    
         
            +
             
     | 
| 
      
 86 
     | 
    
         
            +
              # describe "building the timezone" do
         
     | 
| 
      
 87 
     | 
    
         
            +
              #   
         
     | 
| 
      
 88 
     | 
    
         
            +
              #   it "defines the build method" do
         
     | 
| 
      
 89 
     | 
    
         
            +
              #     Barometer::Yahoo.respond_to?("build_timezone").should be_true
         
     | 
| 
      
 90 
     | 
    
         
            +
              #   end
         
     | 
| 
      
 91 
     | 
    
         
            +
              #   
         
     | 
| 
      
 92 
     | 
    
         
            +
              #   it "requires Hash input" do
         
     | 
| 
      
 93 
     | 
    
         
            +
              #     lambda { Barometer::Yahoo.build_timezone }.should raise_error(ArgumentError)
         
     | 
| 
      
 94 
     | 
    
         
            +
              #     lambda { Barometer::Yahoo.build_timezone({}) }.should_not raise_error(ArgumentError)
         
     | 
| 
      
 95 
     | 
    
         
            +
              #   end
         
     | 
| 
      
 96 
     | 
    
         
            +
              #   
         
     | 
| 
      
 97 
     | 
    
         
            +
              # end
         
     | 
| 
      
 98 
     | 
    
         
            +
              
         
     | 
| 
      
 99 
     | 
    
         
            +
              describe "when measuring" do
         
     | 
| 
      
 100 
     | 
    
         
            +
              
         
     | 
| 
      
 101 
     | 
    
         
            +
                before(:each) do
         
     | 
| 
      
 102 
     | 
    
         
            +
                  @query = Barometer::Query.new("90210")
         
     | 
| 
      
 103 
     | 
    
         
            +
                  @query.preferred = "90210"
         
     | 
| 
      
 104 
     | 
    
         
            +
                  @measurement = Barometer::Measurement.new
         
     | 
| 
      
 105 
     | 
    
         
            +
                  
         
     | 
| 
      
 106 
     | 
    
         
            +
                  FakeWeb.register_uri(:get, 
         
     | 
| 
      
 107 
     | 
    
         
            +
                    "http://weather.yahooapis.com:80/forecastrss?u=c&p=#{CGI.escape(@query.preferred)}",
         
     | 
| 
      
 108 
     | 
    
         
            +
                    :string => File.read(File.join(File.dirname(__FILE__), 
         
     | 
| 
      
 109 
     | 
    
         
            +
                      'fixtures', 
         
     | 
| 
      
 110 
     | 
    
         
            +
                      'yahoo_90210.xml')
         
     | 
| 
      
 111 
     | 
    
         
            +
                    )
         
     | 
| 
      
 112 
     | 
    
         
            +
                  )  
         
     | 
| 
      
 113 
     | 
    
         
            +
                end
         
     | 
| 
      
 114 
     | 
    
         
            +
                
         
     | 
| 
      
 115 
     | 
    
         
            +
                describe "all" do
         
     | 
| 
      
 116 
     | 
    
         
            +
                  
         
     | 
| 
      
 117 
     | 
    
         
            +
                  it "responds to _measure" do
         
     | 
| 
      
 118 
     | 
    
         
            +
                    Barometer::Yahoo.respond_to?("_measure").should be_true
         
     | 
| 
      
 119 
     | 
    
         
            +
                  end
         
     | 
| 
      
 120 
     | 
    
         
            +
                  
         
     | 
| 
      
 121 
     | 
    
         
            +
                  it "requires a Barometer::Measurement object" do
         
     | 
| 
      
 122 
     | 
    
         
            +
                    lambda { Barometer::Yahoo._measure(nil, @query) }.should raise_error(ArgumentError)
         
     | 
| 
      
 123 
     | 
    
         
            +
                    lambda { Barometer::Yahoo._measure("invlaid", @query) }.should raise_error(ArgumentError)
         
     | 
| 
      
 124 
     | 
    
         
            +
              
         
     | 
| 
      
 125 
     | 
    
         
            +
                    lambda { Barometer::Yahoo._measure(@measurement, @query) }.should_not raise_error(ArgumentError)
         
     | 
| 
      
 126 
     | 
    
         
            +
                  end
         
     | 
| 
      
 127 
     | 
    
         
            +
              
         
     | 
| 
      
 128 
     | 
    
         
            +
                  it "requires a Barometer::Query query" do
         
     | 
| 
      
 129 
     | 
    
         
            +
                    lambda { Barometer::Yahoo._measure }.should raise_error(ArgumentError)
         
     | 
| 
      
 130 
     | 
    
         
            +
                    lambda { Barometer::Yahoo._measure(@measurement, 1) }.should raise_error(ArgumentError)
         
     | 
| 
      
 131 
     | 
    
         
            +
                    
         
     | 
| 
      
 132 
     | 
    
         
            +
                    lambda { Barometer::Yahoo._measure(@measurement, @query) }.should_not raise_error(ArgumentError)
         
     | 
| 
      
 133 
     | 
    
         
            +
                  end
         
     | 
| 
      
 134 
     | 
    
         
            +
                  
         
     | 
| 
      
 135 
     | 
    
         
            +
                  it "returns a Barometer::Measurement object" do
         
     | 
| 
      
 136 
     | 
    
         
            +
                    result = Barometer::Yahoo._measure(@measurement, @query)
         
     | 
| 
      
 137 
     | 
    
         
            +
                    result.is_a?(Barometer::Measurement).should be_true
         
     | 
| 
      
 138 
     | 
    
         
            +
                    result.current.is_a?(Barometer::CurrentMeasurement).should be_true
         
     | 
| 
      
 139 
     | 
    
         
            +
                    result.forecast.is_a?(Array).should be_true
         
     | 
| 
      
 140 
     | 
    
         
            +
                    
         
     | 
| 
      
 141 
     | 
    
         
            +
                    result.source.should == :yahoo
         
     | 
| 
      
 142 
     | 
    
         
            +
                  end
         
     | 
| 
      
 143 
     | 
    
         
            +
                  
         
     | 
| 
      
 144 
     | 
    
         
            +
                end
         
     | 
| 
      
 145 
     | 
    
         
            +
              
         
     | 
| 
      
 146 
     | 
    
         
            +
              end
         
     | 
| 
      
 147 
     | 
    
         
            +
              
         
     | 
| 
      
 148 
     | 
    
         
            +
              describe "when answering the simple questions," do
         
     | 
| 
      
 149 
     | 
    
         
            +
                
         
     | 
| 
      
 150 
     | 
    
         
            +
                before(:each) do
         
     | 
| 
      
 151 
     | 
    
         
            +
                  @measurement = Barometer::Measurement.new
         
     | 
| 
      
 152 
     | 
    
         
            +
                end
         
     | 
| 
      
 153 
     | 
    
         
            +
                
         
     | 
| 
      
 154 
     | 
    
         
            +
                describe "currently_wet_by_icon?" do
         
     | 
| 
      
 155 
     | 
    
         
            +
                  
         
     | 
| 
      
 156 
     | 
    
         
            +
                  before(:each) do
         
     | 
| 
      
 157 
     | 
    
         
            +
                    @measurement.current = Barometer::CurrentMeasurement.new
         
     | 
| 
      
 158 
     | 
    
         
            +
                  end
         
     | 
| 
      
 159 
     | 
    
         
            +
             
     | 
| 
      
 160 
     | 
    
         
            +
                  it "returns true if matching icon code" do
         
     | 
| 
      
 161 
     | 
    
         
            +
                    @measurement.current.icon = "4"
         
     | 
| 
      
 162 
     | 
    
         
            +
                    @measurement.current.icon?.should be_true
         
     | 
| 
      
 163 
     | 
    
         
            +
                    Barometer::Yahoo.currently_wet_by_icon?(@measurement.current).should be_true
         
     | 
| 
      
 164 
     | 
    
         
            +
                  end
         
     | 
| 
      
 165 
     | 
    
         
            +
                  
         
     | 
| 
      
 166 
     | 
    
         
            +
                  it "returns false if NO matching icon code" do
         
     | 
| 
      
 167 
     | 
    
         
            +
                    @measurement.current.icon = "32"
         
     | 
| 
      
 168 
     | 
    
         
            +
                    @measurement.current.icon?.should be_true
         
     | 
| 
      
 169 
     | 
    
         
            +
                    Barometer::Yahoo.currently_wet_by_icon?(@measurement.current).should be_false
         
     | 
| 
      
 170 
     | 
    
         
            +
                  end
         
     | 
| 
      
 171 
     | 
    
         
            +
                  
         
     | 
| 
      
 172 
     | 
    
         
            +
                end
         
     | 
| 
      
 173 
     | 
    
         
            +
                
         
     | 
| 
      
 174 
     | 
    
         
            +
                describe "forecasted_wet_by_icon?" do
         
     | 
| 
      
 175 
     | 
    
         
            +
                  
         
     | 
| 
      
 176 
     | 
    
         
            +
                  before(:each) do
         
     | 
| 
      
 177 
     | 
    
         
            +
                    @measurement.forecast = [Barometer::ForecastMeasurement.new]
         
     | 
| 
      
 178 
     | 
    
         
            +
                    @measurement.forecast.first.date = Date.today
         
     | 
| 
      
 179 
     | 
    
         
            +
                    @measurement.forecast.size.should == 1
         
     | 
| 
      
 180 
     | 
    
         
            +
                  end
         
     | 
| 
      
 181 
     | 
    
         
            +
             
     | 
| 
      
 182 
     | 
    
         
            +
                  it "returns true if matching icon code" do
         
     | 
| 
      
 183 
     | 
    
         
            +
                    @measurement.forecast.first.icon = "4"
         
     | 
| 
      
 184 
     | 
    
         
            +
                    @measurement.forecast.first.icon?.should be_true
         
     | 
| 
      
 185 
     | 
    
         
            +
                    Barometer::Yahoo.forecasted_wet_by_icon?(@measurement.forecast.first).should be_true
         
     | 
| 
      
 186 
     | 
    
         
            +
                  end
         
     | 
| 
      
 187 
     | 
    
         
            +
                  
         
     | 
| 
      
 188 
     | 
    
         
            +
                  it "returns false if NO matching icon code" do
         
     | 
| 
      
 189 
     | 
    
         
            +
                    @measurement.forecast.first.icon = "32"
         
     | 
| 
      
 190 
     | 
    
         
            +
                    @measurement.forecast.first.icon?.should be_true
         
     | 
| 
      
 191 
     | 
    
         
            +
                    Barometer::Yahoo.forecasted_wet_by_icon?(@measurement.forecast.first).should be_false
         
     | 
| 
      
 192 
     | 
    
         
            +
                  end
         
     | 
| 
      
 193 
     | 
    
         
            +
                  
         
     | 
| 
      
 194 
     | 
    
         
            +
                end
         
     | 
| 
      
 195 
     | 
    
         
            +
                
         
     | 
| 
      
 196 
     | 
    
         
            +
                describe "currently_sunny_by_icon?" do
         
     | 
| 
      
 197 
     | 
    
         
            +
                  
         
     | 
| 
      
 198 
     | 
    
         
            +
                  before(:each) do
         
     | 
| 
      
 199 
     | 
    
         
            +
                    @measurement.current = Barometer::CurrentMeasurement.new
         
     | 
| 
      
 200 
     | 
    
         
            +
                  end
         
     | 
| 
      
 201 
     | 
    
         
            +
             
     | 
| 
      
 202 
     | 
    
         
            +
                  it "returns true if matching icon code" do
         
     | 
| 
      
 203 
     | 
    
         
            +
                    @measurement.current.icon = "32"
         
     | 
| 
      
 204 
     | 
    
         
            +
                    @measurement.current.icon?.should be_true
         
     | 
| 
      
 205 
     | 
    
         
            +
                    Barometer::Yahoo.currently_sunny_by_icon?(@measurement.current).should be_true
         
     | 
| 
      
 206 
     | 
    
         
            +
                  end
         
     | 
| 
      
 207 
     | 
    
         
            +
                  
         
     | 
| 
      
 208 
     | 
    
         
            +
                  it "returns false if NO matching icon code" do
         
     | 
| 
      
 209 
     | 
    
         
            +
                    @measurement.current.icon = "4"
         
     | 
| 
      
 210 
     | 
    
         
            +
                    @measurement.current.icon?.should be_true
         
     | 
| 
      
 211 
     | 
    
         
            +
                    Barometer::Yahoo.currently_sunny_by_icon?(@measurement.current).should be_false
         
     | 
| 
      
 212 
     | 
    
         
            +
                  end
         
     | 
| 
      
 213 
     | 
    
         
            +
                  
         
     | 
| 
      
 214 
     | 
    
         
            +
                end
         
     | 
| 
      
 215 
     | 
    
         
            +
                
         
     | 
| 
      
 216 
     | 
    
         
            +
                describe "forecasted_sunny_by_icon?" do
         
     | 
| 
      
 217 
     | 
    
         
            +
                  
         
     | 
| 
      
 218 
     | 
    
         
            +
                  before(:each) do
         
     | 
| 
      
 219 
     | 
    
         
            +
                    @measurement.forecast = [Barometer::ForecastMeasurement.new]
         
     | 
| 
      
 220 
     | 
    
         
            +
                    @measurement.forecast.first.date = Date.today
         
     | 
| 
      
 221 
     | 
    
         
            +
                    @measurement.forecast.size.should == 1
         
     | 
| 
      
 222 
     | 
    
         
            +
                  end
         
     | 
| 
      
 223 
     | 
    
         
            +
             
     | 
| 
      
 224 
     | 
    
         
            +
                  it "returns true if matching icon code" do
         
     | 
| 
      
 225 
     | 
    
         
            +
                    @measurement.forecast.first.icon = "32"
         
     | 
| 
      
 226 
     | 
    
         
            +
                    @measurement.forecast.first.icon?.should be_true
         
     | 
| 
      
 227 
     | 
    
         
            +
                    Barometer::Yahoo.forecasted_sunny_by_icon?(@measurement.forecast.first).should be_true
         
     | 
| 
      
 228 
     | 
    
         
            +
                  end
         
     | 
| 
      
 229 
     | 
    
         
            +
                  
         
     | 
| 
      
 230 
     | 
    
         
            +
                  it "returns false if NO matching icon code" do
         
     | 
| 
      
 231 
     | 
    
         
            +
                    @measurement.forecast.first.icon = "4"
         
     | 
| 
      
 232 
     | 
    
         
            +
                    @measurement.forecast.first.icon?.should be_true
         
     | 
| 
      
 233 
     | 
    
         
            +
                    Barometer::Yahoo.forecasted_sunny_by_icon?(@measurement.forecast.first).should be_false
         
     | 
| 
      
 234 
     | 
    
         
            +
                  end
         
     | 
| 
      
 235 
     | 
    
         
            +
                  
         
     | 
| 
      
 236 
     | 
    
         
            +
                end
         
     | 
| 
      
 237 
     | 
    
         
            +
                
         
     | 
| 
      
 238 
     | 
    
         
            +
              end
         
     | 
| 
      
 239 
     | 
    
         
            +
              
         
     | 
| 
      
 240 
     | 
    
         
            +
              describe "overall data correctness" do
         
     | 
| 
      
 241 
     | 
    
         
            +
                
         
     | 
| 
      
 242 
     | 
    
         
            +
                before(:each) do
         
     | 
| 
      
 243 
     | 
    
         
            +
                  @query = Barometer::Query.new("90210")
         
     | 
| 
      
 244 
     | 
    
         
            +
                  @query.preferred = "90210"
         
     | 
| 
      
 245 
     | 
    
         
            +
                  @measurement = Barometer::Measurement.new
         
     | 
| 
      
 246 
     | 
    
         
            +
             
     | 
| 
      
 247 
     | 
    
         
            +
                  FakeWeb.register_uri(:get, 
         
     | 
| 
      
 248 
     | 
    
         
            +
                    "http://weather.yahooapis.com:80/forecastrss?u=c&p=#{CGI.escape(@query.preferred)}",
         
     | 
| 
      
 249 
     | 
    
         
            +
                    :string => File.read(File.join(File.dirname(__FILE__), 
         
     | 
| 
      
 250 
     | 
    
         
            +
                      'fixtures', 
         
     | 
| 
      
 251 
     | 
    
         
            +
                      'yahoo_90210.xml')
         
     | 
| 
      
 252 
     | 
    
         
            +
                    )
         
     | 
| 
      
 253 
     | 
    
         
            +
                  )  
         
     | 
| 
      
 254 
     | 
    
         
            +
                end
         
     | 
| 
      
 255 
     | 
    
         
            +
             
     | 
| 
      
 256 
     | 
    
         
            +
                # TODO: complete this
         
     | 
| 
      
 257 
     | 
    
         
            +
                it "should correctly build the data" do
         
     | 
| 
      
 258 
     | 
    
         
            +
                  result = Barometer::Yahoo._measure(@measurement, @query)
         
     | 
| 
      
 259 
     | 
    
         
            +
                  
         
     | 
| 
      
 260 
     | 
    
         
            +
                  sun_rise = Barometer::Zone.merge("6:09 am", "Sun, 26 Apr 2009 10:51 am PDT", "PDT")
         
     | 
| 
      
 261 
     | 
    
         
            +
                  sun_set = Barometer::Zone.merge("7:34 pm", "Sun, 26 Apr 2009 10:51 am PDT", "PDT")
         
     | 
| 
      
 262 
     | 
    
         
            +
                  
         
     | 
| 
      
 263 
     | 
    
         
            +
                  # build current
         
     | 
| 
      
 264 
     | 
    
         
            +
                  @measurement.current.sun.rise.should == sun_rise
         
     | 
| 
      
 265 
     | 
    
         
            +
                  @measurement.current.sun.set.should == sun_set
         
     | 
| 
      
 266 
     | 
    
         
            +
                  
         
     | 
| 
      
 267 
     | 
    
         
            +
                  # builds location
         
     | 
| 
      
 268 
     | 
    
         
            +
                  @measurement.location.city.should == "Beverly Hills"
         
     | 
| 
      
 269 
     | 
    
         
            +
                  
         
     | 
| 
      
 270 
     | 
    
         
            +
                  # builds forecasts
         
     | 
| 
      
 271 
     | 
    
         
            +
                  @measurement.forecast.size.should == 2
         
     | 
| 
      
 272 
     | 
    
         
            +
                  
         
     | 
| 
      
 273 
     | 
    
         
            +
                  @measurement.forecast[0].condition.should == "Mostly Sunny"
         
     | 
| 
      
 274 
     | 
    
         
            +
                  @measurement.forecast[0].icon.should == "34"
         
     | 
| 
      
 275 
     | 
    
         
            +
                  @measurement.forecast[0].sun.rise.should == sun_rise + (60*60*24*0)
         
     | 
| 
      
 276 
     | 
    
         
            +
                  @measurement.forecast[0].sun.set.should == sun_set + (60*60*24*0)
         
     | 
| 
      
 277 
     | 
    
         
            +
                  
         
     | 
| 
      
 278 
     | 
    
         
            +
                  @measurement.forecast[1].condition.should == "Cloudy"
         
     | 
| 
      
 279 
     | 
    
         
            +
                  @measurement.forecast[1].icon.should == "26"
         
     | 
| 
      
 280 
     | 
    
         
            +
                  @measurement.forecast[1].sun.rise.should == sun_rise + (60*60*24*1)
         
     | 
| 
      
 281 
     | 
    
         
            +
                  @measurement.forecast[1].sun.set.should == sun_set + (60*60*24*1)
         
     | 
| 
      
 282 
     | 
    
         
            +
                  
         
     | 
| 
      
 283 
     | 
    
         
            +
                end
         
     | 
| 
      
 284 
     | 
    
         
            +
                # <yweather:location city="Beverly Hills" region="CA" country="US"/>
         
     | 
| 
      
 285 
     | 
    
         
            +
                # <yweather:units temperature="C" distance="km" pressure="mb" speed="kph"/>
         
     | 
| 
      
 286 
     | 
    
         
            +
                # <yweather:wind chill="17" direction="0" speed="4.83" />
         
     | 
| 
      
 287 
     | 
    
         
            +
                # <yweather:atmosphere humidity="50" visibility="16.09" pressure="1017" rising="0" />
         
     | 
| 
      
 288 
     | 
    
         
            +
                # <item>
         
     | 
| 
      
 289 
     | 
    
         
            +
                #   <geo:lat>34.08</geo:lat>
         
     | 
| 
      
 290 
     | 
    
         
            +
                #   <geo:long>-118.4</geo:long>
         
     | 
| 
      
 291 
     | 
    
         
            +
                #   <pubDate>Sun, 26 Apr 2009 10:51 am PDT</pubDate>
         
     | 
| 
      
 292 
     | 
    
         
            +
                #   <yweather:condition text="Partly Cloudy" code="30" temp="17" date="Sun, 26 Apr 2009 10:51 am PDT" />
         
     | 
| 
      
 293 
     | 
    
         
            +
                #   <yweather:forecast day="Sun" date="26 Apr 2009" low="11" high="19" 
         
     | 
| 
      
 294 
     | 
    
         
            +
                #   <yweather:forecast day="Mon" date="27 Apr 2009" low="11" high="18"
         
     | 
| 
      
 295 
     | 
    
         
            +
                # </item>
         
     | 
| 
      
 296 
     | 
    
         
            +
                
         
     | 
| 
      
 297 
     | 
    
         
            +
              end
         
     | 
| 
      
 298 
     | 
    
         
            +
              
         
     | 
| 
      
 299 
     | 
    
         
            +
            end
         
     |