barometer 0.6.7 → 0.7.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.
Files changed (50) hide show
  1. data/.gitignore +4 -0
  2. data/Gemfile +3 -0
  3. data/LICENSE +1 -1
  4. data/README.rdoc +36 -8
  5. data/Rakefile +7 -28
  6. data/TODO +4 -0
  7. data/VERSION.yml +2 -2
  8. data/barometer.gemspec +20 -193
  9. data/bin/barometer +8 -5
  10. data/lib/barometer.rb +5 -1
  11. data/lib/barometer/data/local_datetime.rb +11 -7
  12. data/lib/barometer/formats.rb +2 -1
  13. data/lib/barometer/formats/coordinates.rb +15 -3
  14. data/lib/barometer/formats/format.rb +18 -0
  15. data/lib/barometer/formats/geocode.rb +12 -5
  16. data/lib/barometer/formats/weather_id.rb +0 -15
  17. data/lib/barometer/formats/woe_id.rb +150 -0
  18. data/lib/barometer/query.rb +20 -4
  19. data/lib/barometer/services.rb +2 -1
  20. data/lib/barometer/weather_services/service.rb +0 -4
  21. data/lib/barometer/weather_services/weather_bug.rb +2 -2
  22. data/lib/barometer/weather_services/yahoo.rb +14 -3
  23. data/lib/barometer/web_services/placemaker.rb +95 -0
  24. data/lib/barometer/web_services/web_service.rb +1 -4
  25. data/spec/barometer_spec.rb +14 -32
  26. data/spec/data/local_datetime_spec.rb +7 -2
  27. data/spec/data/zone_spec.rb +5 -2
  28. data/spec/fakeweb_helper.rb +158 -0
  29. data/spec/fixtures/services/placemaker/T5B4M9.xml +65 -0
  30. data/spec/fixtures/services/placemaker/atlanta.xml +65 -0
  31. data/spec/fixtures/services/placemaker/coords.xml +65 -0
  32. data/spec/fixtures/services/placemaker/ksfo.xml +65 -0
  33. data/spec/fixtures/services/placemaker/new_york.xml +65 -0
  34. data/spec/fixtures/services/placemaker/the_hills.xml +65 -0
  35. data/spec/fixtures/services/placemaker/w615702.xml +46 -0
  36. data/spec/fixtures/services/weather_bug/90210_forecast.xml +1 -1
  37. data/spec/formats/coordinates_spec.rb +16 -0
  38. data/spec/formats/format_spec.rb +9 -0
  39. data/spec/formats/woe_id_spec.rb +215 -0
  40. data/spec/query_spec.rb +38 -0
  41. data/spec/spec_helper.rb +7 -160
  42. data/spec/weather_services/google_spec.rb +0 -8
  43. data/spec/weather_services/services_spec.rb +1 -1
  44. data/spec/weather_services/weather_bug_spec.rb +0 -36
  45. data/spec/weather_services/weather_dot_com_spec.rb +0 -20
  46. data/spec/weather_services/wunderground_spec.rb +0 -30
  47. data/spec/weather_services/yahoo_spec.rb +1 -17
  48. data/spec/web_services/placemaker_spec.rb +46 -0
  49. metadata +136 -18
  50. data/lib/barometer/extensions/httparty.rb +0 -21
@@ -0,0 +1,65 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <contentlocation xmlns:yahoo="http://www.yahooapis.com/v1/base.rng" xmlns="http://wherein.yahooapis.com/v1/schema" xml:lang="en">
3
+ <processingTime>0.000988</processingTime>
4
+ <version> build 091119</version>
5
+ <documentLength>15</documentLength>
6
+ <document>
7
+ <administrativeScope>
8
+ <woeId>2357024</woeId>
9
+ <type>Town</type>
10
+ <name><![CDATA[Atlanta, GA, US]]></name>
11
+ <centroid>
12
+ <latitude>33.7483</latitude>
13
+ <longitude>-84.3911</longitude>
14
+ </centroid>
15
+ </administrativeScope>
16
+ <geographicScope>
17
+ <woeId>2357024</woeId>
18
+ <type>Town</type>
19
+ <name><![CDATA[Atlanta, GA, US]]></name>
20
+ <centroid>
21
+ <latitude>33.7483</latitude>
22
+ <longitude>-84.3911</longitude>
23
+ </centroid>
24
+ </geographicScope>
25
+ <extents>
26
+ <center>
27
+ <latitude>33.7483</latitude>
28
+ <longitude>-84.3911</longitude>
29
+ </center>
30
+ <southWest>
31
+ <latitude>33.5548</latitude>
32
+ <longitude>-84.566</longitude>
33
+ </southWest>
34
+ <northEast>
35
+ <latitude>34.012</latitude>
36
+ <longitude>-84.2671</longitude>
37
+ </northEast>
38
+ </extents>
39
+ <placeDetails>
40
+ <place>
41
+ <woeId>2357024</woeId>
42
+ <type>Town</type>
43
+ <name><![CDATA[Atlanta, GA, US]]></name>
44
+ <centroid>
45
+ <latitude>33.7483</latitude>
46
+ <longitude>-84.3911</longitude>
47
+ </centroid>
48
+ </place>
49
+ <matchType>0</matchType>
50
+ <weight>1</weight>
51
+ <confidence>10</confidence>
52
+ </placeDetails>
53
+ <referenceList>
54
+ <reference>
55
+ <woeIds>2357024</woeIds>
56
+ <start>0</start>
57
+ <end>15</end>
58
+ <isPlaintextMarker>1</isPlaintextMarker>
59
+ <text><![CDATA[Atlanta, GA, US]]></text>
60
+ <type>plaintext</type>
61
+ <xpath><![CDATA[]]></xpath>
62
+ </reference>
63
+ </referenceList>
64
+ </document>
65
+ </contentlocation>
@@ -0,0 +1,65 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <contentlocation xmlns:yahoo="http://www.yahooapis.com/v1/base.rng" xmlns="http://wherein.yahooapis.com/v1/schema" xml:lang="en">
3
+ <processingTime>0.002971</processingTime>
4
+ <version> build 091119</version>
5
+ <documentLength>103</documentLength>
6
+ <document>
7
+ <administrativeScope>
8
+ <woeId>2459115</woeId>
9
+ <type>Town</type>
10
+ <name><![CDATA[New York, NY, US]]></name>
11
+ <centroid>
12
+ <latitude>40.7146</latitude>
13
+ <longitude>-74.0071</longitude>
14
+ </centroid>
15
+ </administrativeScope>
16
+ <geographicScope>
17
+ <woeId>12761333</woeId>
18
+ <type>Zip</type>
19
+ <name><![CDATA[10001, New York, NY, US]]></name>
20
+ <centroid>
21
+ <latitude>40.7508</latitude>
22
+ <longitude>-73.9994</longitude>
23
+ </centroid>
24
+ </geographicScope>
25
+ <extents>
26
+ <center>
27
+ <latitude>40.7561</latitude>
28
+ <longitude>-73.987</longitude>
29
+ </center>
30
+ <southWest>
31
+ <latitude>40.7434</latitude>
32
+ <longitude>-74.0148</longitude>
33
+ </southWest>
34
+ <northEast>
35
+ <latitude>40.7582</latitude>
36
+ <longitude>-73.984</longitude>
37
+ </northEast>
38
+ </extents>
39
+ <placeDetails>
40
+ <place>
41
+ <woeId>12761333</woeId>
42
+ <type>Zip</type>
43
+ <name><![CDATA[10001, New York, NY, US]]></name>
44
+ <centroid>
45
+ <latitude>40.7561</latitude>
46
+ <longitude>-73.987</longitude>
47
+ </centroid>
48
+ </place>
49
+ <matchType>1</matchType>
50
+ <weight>1</weight>
51
+ <confidence>10</confidence>
52
+ </placeDetails>
53
+ <referenceList>
54
+ <reference>
55
+ <woeIds>12761333</woeIds>
56
+ <start>-1</start>
57
+ <end>-1</end>
58
+ <isPlaintextMarker>0</isPlaintextMarker>
59
+ <text><![CDATA[]]></text>
60
+ <type>xpath</type>
61
+ <xpath><![CDATA[/div[1]/span[2]]]></xpath>
62
+ </reference>
63
+ </referenceList>
64
+ </document>
65
+ </contentlocation>
@@ -0,0 +1,65 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <contentlocation xmlns:yahoo="http://www.yahooapis.com/v1/base.rng" xmlns="http://wherein.yahooapis.com/v1/schema" xml:lang="en">
3
+ <processingTime>0.001045</processingTime>
4
+ <version> build 091119</version>
5
+ <documentLength>17</documentLength>
6
+ <document>
7
+ <administrativeScope>
8
+ <woeId>2451206</woeId>
9
+ <type>Town</type>
10
+ <name><![CDATA[Millbrae, CA, US]]></name>
11
+ <centroid>
12
+ <latitude>37.6028</latitude>
13
+ <longitude>-122.395</longitude>
14
+ </centroid>
15
+ </administrativeScope>
16
+ <geographicScope>
17
+ <woeId>2451206</woeId>
18
+ <type>Town</type>
19
+ <name><![CDATA[Millbrae, CA, US]]></name>
20
+ <centroid>
21
+ <latitude>37.6028</latitude>
22
+ <longitude>-122.395</longitude>
23
+ </centroid>
24
+ </geographicScope>
25
+ <extents>
26
+ <center>
27
+ <latitude>37.6028</latitude>
28
+ <longitude>-122.395</longitude>
29
+ </center>
30
+ <southWest>
31
+ <latitude>37.5811</latitude>
32
+ <longitude>-122.429</longitude>
33
+ </southWest>
34
+ <northEast>
35
+ <latitude>37.6181</latitude>
36
+ <longitude>-122.373</longitude>
37
+ </northEast>
38
+ </extents>
39
+ <placeDetails>
40
+ <place>
41
+ <woeId>2451206</woeId>
42
+ <type>Town</type>
43
+ <name><![CDATA[Millbrae, CA, US]]></name>
44
+ <centroid>
45
+ <latitude>37.6028</latitude>
46
+ <longitude>-122.395</longitude>
47
+ </centroid>
48
+ </place>
49
+ <matchType>0</matchType>
50
+ <weight>1</weight>
51
+ <confidence>10</confidence>
52
+ </placeDetails>
53
+ <referenceList>
54
+ <reference>
55
+ <woeIds>2451206</woeIds>
56
+ <start>0</start>
57
+ <end>17</end>
58
+ <isPlaintextMarker>1</isPlaintextMarker>
59
+ <text><![CDATA[Millbrae, CA, USA]]></text>
60
+ <type>plaintext</type>
61
+ <xpath><![CDATA[]]></xpath>
62
+ </reference>
63
+ </referenceList>
64
+ </document>
65
+ </contentlocation>
@@ -0,0 +1,65 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <contentlocation xmlns:yahoo="http://www.yahooapis.com/v1/base.rng" xmlns="http://wherein.yahooapis.com/v1/schema" xml:lang="en">
3
+ <processingTime>0.001008</processingTime>
4
+ <version> build 091119</version>
5
+ <documentLength>12</documentLength>
6
+ <document>
7
+ <administrativeScope>
8
+ <woeId>2459115</woeId>
9
+ <type>Town</type>
10
+ <name><![CDATA[New York, NY, US]]></name>
11
+ <centroid>
12
+ <latitude>40.7146</latitude>
13
+ <longitude>-74.0071</longitude>
14
+ </centroid>
15
+ </administrativeScope>
16
+ <geographicScope>
17
+ <woeId>24701772</woeId>
18
+ <type>Zone</type>
19
+ <name><![CDATA[212 New York, NY, US]]></name>
20
+ <centroid>
21
+ <latitude>40.791</latitude>
22
+ <longitude>-73.9659</longitude>
23
+ </centroid>
24
+ </geographicScope>
25
+ <extents>
26
+ <center>
27
+ <latitude>40.7146</latitude>
28
+ <longitude>-74.0071</longitude>
29
+ </center>
30
+ <southWest>
31
+ <latitude>40.4957</latitude>
32
+ <longitude>-74.2557</longitude>
33
+ </southWest>
34
+ <northEast>
35
+ <latitude>40.9176</latitude>
36
+ <longitude>-73.6895</longitude>
37
+ </northEast>
38
+ </extents>
39
+ <placeDetails>
40
+ <place>
41
+ <woeId>2459115</woeId>
42
+ <type>Town</type>
43
+ <name><![CDATA[New York, NY, US]]></name>
44
+ <centroid>
45
+ <latitude>40.7146</latitude>
46
+ <longitude>-74.0071</longitude>
47
+ </centroid>
48
+ </place>
49
+ <matchType>0</matchType>
50
+ <weight>1</weight>
51
+ <confidence>10</confidence>
52
+ </placeDetails>
53
+ <referenceList>
54
+ <reference>
55
+ <woeIds>2459115</woeIds>
56
+ <start>0</start>
57
+ <end>12</end>
58
+ <isPlaintextMarker>1</isPlaintextMarker>
59
+ <text><![CDATA[New York, NY]]></text>
60
+ <type>plaintext</type>
61
+ <xpath><![CDATA[]]></xpath>
62
+ </reference>
63
+ </referenceList>
64
+ </document>
65
+ </contentlocation>
@@ -0,0 +1,65 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <contentlocation xmlns:yahoo="http://www.yahooapis.com/v1/base.rng" xmlns="http://wherein.yahooapis.com/v1/schema" xml:lang="en">
3
+ <processingTime>0.001045</processingTime>
4
+ <version> build 091119</version>
5
+ <documentLength>22</documentLength>
6
+ <document>
7
+ <administrativeScope>
8
+ <woeId>2363796</woeId>
9
+ <type>Town</type>
10
+ <name><![CDATA[Beverly Hills, CA, US]]></name>
11
+ <centroid>
12
+ <latitude>34.0729</latitude>
13
+ <longitude>-118.4</longitude>
14
+ </centroid>
15
+ </administrativeScope>
16
+ <geographicScope>
17
+ <woeId>2363796</woeId>
18
+ <type>Town</type>
19
+ <name><![CDATA[Beverly Hills, CA, US]]></name>
20
+ <centroid>
21
+ <latitude>34.0729</latitude>
22
+ <longitude>-118.4</longitude>
23
+ </centroid>
24
+ </geographicScope>
25
+ <extents>
26
+ <center>
27
+ <latitude>34.0729</latitude>
28
+ <longitude>-118.4</longitude>
29
+ </center>
30
+ <southWest>
31
+ <latitude>34.0541</latitude>
32
+ <longitude>-118.439</longitude>
33
+ </southWest>
34
+ <northEast>
35
+ <latitude>34.1296</latitude>
36
+ <longitude>-118.372</longitude>
37
+ </northEast>
38
+ </extents>
39
+ <placeDetails>
40
+ <place>
41
+ <woeId>2363796</woeId>
42
+ <type>Town</type>
43
+ <name><![CDATA[Beverly Hills, CA, US]]></name>
44
+ <centroid>
45
+ <latitude>34.0729</latitude>
46
+ <longitude>-118.4</longitude>
47
+ </centroid>
48
+ </place>
49
+ <matchType>0</matchType>
50
+ <weight>1</weight>
51
+ <confidence>10</confidence>
52
+ </placeDetails>
53
+ <referenceList>
54
+ <reference>
55
+ <woeIds>2363796</woeIds>
56
+ <start>0</start>
57
+ <end>22</end>
58
+ <isPlaintextMarker>1</isPlaintextMarker>
59
+ <text><![CDATA[Beverly Hills, CA, USA]]></text>
60
+ <type>plaintext</type>
61
+ <xpath><![CDATA[]]></xpath>
62
+ </reference>
63
+ </referenceList>
64
+ </document>
65
+ </contentlocation>
@@ -0,0 +1,46 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2
+ <rss xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" version="2.0">
3
+ <channel>
4
+ <title>Yahoo! Weather - Paris, FR</title>
5
+ <link>http://us.rd.yahoo.com/dailynews/rss/weather/Paris__FR/*http://weather.yahoo.com/forecast/FRXX0076_f.html</link>
6
+ <description>Yahoo! Weather for Paris, FR</description>
7
+ <language>en-us</language>
8
+ <lastBuildDate>Wed, 17 Feb 2010 9:00 am CET</lastBuildDate>
9
+ <ttl>60</ttl>
10
+ <yweather:location city="Paris" region="" country="France"/>
11
+ <yweather:units temperature="F" distance="mi" pressure="in" speed="mph"/>
12
+ <yweather:wind chill="34" direction="0" speed="3"/>
13
+ <yweather:atmosphere humidity="93" visibility="2.17" pressure="29.23" rising="0"/>
14
+ <yweather:astronomy sunrise="7:55 am" sunset="6:14 pm"/>
15
+ <image>
16
+ <title>Yahoo! Weather</title>
17
+ <width>142</width>
18
+ <height>18</height>
19
+ <link>http://weather.yahoo.com</link>
20
+ <url>http://l.yimg.com/a/i/us/nws/th/main_142b.gif</url>
21
+ </image>
22
+ <item>
23
+ <title>Conditions for Paris, FR at 9:00 am CET</title>
24
+ <geo:lat>48.86</geo:lat>
25
+ <geo:long>2.34</geo:long>
26
+ <link>http://us.rd.yahoo.com/dailynews/rss/weather/Paris__FR/*http://weather.yahoo.com/forecast/FRXX0076_f.html</link>
27
+ <pubDate>Wed, 17 Feb 2010 9:00 am CET</pubDate>
28
+ <yweather:condition text="Light Rain" code="11" temp="34" date="Wed, 17 Feb 2010 9:00 am CET"/>
29
+ <description><![CDATA[
30
+ <img src="http://l.yimg.com/a/i/us/we/52/11.gif"/><br />
31
+ <b>Current Conditions:</b><br />
32
+ Light Rain, 34 F<BR />
33
+ <BR /><b>Forecast:</b><BR />
34
+ Wed - Rain/Snow. High: 39 Low: 35<br />
35
+ Thu - AM Fog/PM Clouds. High: 43 Low: 36<br />
36
+ <br />
37
+ <a href="http://us.rd.yahoo.com/dailynews/rss/weather/Paris__FR/*http://weather.yahoo.com/forecast/FRXX0076_f.html">Full Forecast at Yahoo! Weather</a><BR/><BR/>
38
+ (provided by <a href="http://www.weather.com" >The Weather Channel</a>)<br/>
39
+ ]]></description>
40
+ <yweather:forecast day="Wed" date="17 Feb 2010" low="35" high="39" text="Rain/Snow" code="5"/>
41
+ <yweather:forecast day="Thu" date="18 Feb 2010" low="36" high="43" text="AM Fog/PM Clouds" code="20"/>
42
+ <guid isPermaLink="false">FRXX0076_2010_02_17_9_00_CET</guid>
43
+ </item>
44
+ </channel>
45
+ </rss>
46
+ <!-- api4.weather.ac4.yahoo.com uncompressed/chunked Wed Feb 17 00:36:01 PST 2010 -->
@@ -1 +1 @@
1
- <aws:weather xmlns:aws="http://www.aws.com/aws"><aws:api version="2.0" /><aws:WebURL>http://weather.weatherbug.com/CA/Beverly Hills-weather/local-forecast/7-day-forecast.html?ZCode=Z5546&amp;Units=1</aws:WebURL><aws:forecasts type="Detailed" date="5/15/2009 8:26:00 AM"><aws:location><aws:city>Beverly Hills</aws:city><aws:state>CA</aws:state><aws:zip>90210</aws:zip><aws:zone>CA041</aws:zone></aws:location><aws:forecast><aws:title alttitle="FRI">Friday</aws:title><aws:short-prediction>Partly Cloudy</aws:short-prediction><aws:image isNight="0" icon="cond003.gif">http://deskwx.weatherbug.com/images/Forecast/icons/cond003.gif</aws:image><aws:description>Friday</aws:description><aws:prediction>Areas of low clouds and fog in the morning then sunny. Highs in the upper 60s to mid 70s at the beaches to the lower 80s inland.</aws:prediction><aws:high units="&amp;deg;C">27</aws:high><aws:low units="&amp;deg;C">17</aws:low></aws:forecast><aws:forecast><aws:title alttitle="SAT">Saturday</aws:title><aws:short-prediction>Partly Cloudy</aws:short-prediction><aws:image isNight="0" icon="cond003.gif">http://deskwx.weatherbug.com/images/Forecast/icons/cond003.gif</aws:image><aws:description>Saturday</aws:description><aws:prediction>Areas of low clouds and fog in the morning then sunny. Highs in the lower to mid 70s at the beaches to the lower to mid 80s inland.</aws:prediction><aws:high units="&amp;deg;C">28</aws:high><aws:low units="&amp;deg;C">17</aws:low></aws:forecast><aws:forecast><aws:title alttitle="SUN">Sunday</aws:title><aws:short-prediction>Partly Cloudy</aws:short-prediction><aws:image isNight="0" icon="cond003.gif">http://deskwx.weatherbug.com/images/Forecast/icons/cond003.gif</aws:image><aws:description>Sunday</aws:description><aws:prediction>Areas of low clouds and fog in the morning then sunny. Highs in the lower to mid 70s at the beaches to the lower to mid 80s inland.</aws:prediction><aws:high units="&amp;deg;C">28</aws:high><aws:low units="&amp;deg;C">17</aws:low></aws:forecast><aws:forecast><aws:title alttitle="MON">Monday</aws:title><aws:short-prediction>Mostly Sunny</aws:short-prediction><aws:image isNight="0" icon="cond026.gif">http://deskwx.weatherbug.com/images/Forecast/icons/cond026.gif</aws:image><aws:description>Monday</aws:description><aws:prediction>Areas of low clouds and fog in the morning then mostly sunny. Highs around 70 at the beaches to around 80 inland.</aws:prediction><aws:high units="&amp;deg;C">26</aws:high><aws:low units="&amp;deg;C">16</aws:low></aws:forecast><aws:forecast><aws:title alttitle="TUE">Tuesday</aws:title><aws:short-prediction>Mostly Sunny</aws:short-prediction><aws:image isNight="0" icon="cond026.gif">http://deskwx.weatherbug.com/images/Forecast/icons/cond026.gif</aws:image><aws:description>Tuesday</aws:description><aws:prediction>Night through morning low clouds and fog...otherwise mostly clear. Lows around 60. Highs in the mid to upper 60s at the beaches to the 70s inland.</aws:prediction><aws:high units="&amp;deg;C">25</aws:high><aws:low units="&amp;deg;C">16</aws:low></aws:forecast><aws:forecast><aws:title alttitle="WED">Wednesday</aws:title><aws:short-prediction>Mostly Sunny</aws:short-prediction><aws:image isNight="0" icon="cond026.gif">http://deskwx.weatherbug.com/images/Forecast/icons/cond026.gif</aws:image><aws:description>Wednesday</aws:description><aws:prediction>Night through morning low clouds and fog...otherwise mostly clear. Lows around 60. Highs in the mid to upper 60s at the beaches to the 70s inland.</aws:prediction><aws:high units="&amp;deg;C">24</aws:high><aws:low units="&amp;deg;C">16</aws:low></aws:forecast><aws:forecast><aws:title alttitle="THU">Thursday</aws:title><aws:short-prediction>Mostly Sunny</aws:short-prediction><aws:image isNight="0" icon="cond026.gif">http://deskwx.weatherbug.com/images/Forecast/icons/cond026.gif</aws:image><aws:description>Thursday</aws:description><aws:prediction>Night through morning low clouds and fog...otherwise mostly clear. Lows around 60. Highs in the mid to upper 60s at the beaches to the 70s inland.</aws:prediction><aws:high units="&amp;deg;C">24</aws:high><aws:low units="&amp;deg;C">--</aws:low></aws:forecast></aws:forecasts></aws:weather>
1
+ <aws:weather xmlns:aws="http://www.aws.com/aws"><aws:api version="2.0" /><aws:WebURL>http://weather.weatherbug.com/CA/Beverly Hills-weather/local-forecast/7-day-forecast.html?ZCode=Z5546&amp;Units=1</aws:WebURL><aws:forecasts type="Detailed" date="Fri, 15 May 2009 8:26:00 GMT"><aws:location><aws:city>Beverly Hills</aws:city><aws:state>CA</aws:state><aws:zip>90210</aws:zip><aws:zone>CA041</aws:zone></aws:location><aws:forecast><aws:title alttitle="FRI">Friday</aws:title><aws:short-prediction>Partly Cloudy</aws:short-prediction><aws:image isNight="0" icon="cond003.gif">http://deskwx.weatherbug.com/images/Forecast/icons/cond003.gif</aws:image><aws:description>Friday</aws:description><aws:prediction>Areas of low clouds and fog in the morning then sunny. Highs in the upper 60s to mid 70s at the beaches to the lower 80s inland.</aws:prediction><aws:high units="&amp;deg;C">27</aws:high><aws:low units="&amp;deg;C">17</aws:low></aws:forecast><aws:forecast><aws:title alttitle="SAT">Saturday</aws:title><aws:short-prediction>Partly Cloudy</aws:short-prediction><aws:image isNight="0" icon="cond003.gif">http://deskwx.weatherbug.com/images/Forecast/icons/cond003.gif</aws:image><aws:description>Saturday</aws:description><aws:prediction>Areas of low clouds and fog in the morning then sunny. Highs in the lower to mid 70s at the beaches to the lower to mid 80s inland.</aws:prediction><aws:high units="&amp;deg;C">28</aws:high><aws:low units="&amp;deg;C">17</aws:low></aws:forecast><aws:forecast><aws:title alttitle="SUN">Sunday</aws:title><aws:short-prediction>Partly Cloudy</aws:short-prediction><aws:image isNight="0" icon="cond003.gif">http://deskwx.weatherbug.com/images/Forecast/icons/cond003.gif</aws:image><aws:description>Sunday</aws:description><aws:prediction>Areas of low clouds and fog in the morning then sunny. Highs in the lower to mid 70s at the beaches to the lower to mid 80s inland.</aws:prediction><aws:high units="&amp;deg;C">28</aws:high><aws:low units="&amp;deg;C">17</aws:low></aws:forecast><aws:forecast><aws:title alttitle="MON">Monday</aws:title><aws:short-prediction>Mostly Sunny</aws:short-prediction><aws:image isNight="0" icon="cond026.gif">http://deskwx.weatherbug.com/images/Forecast/icons/cond026.gif</aws:image><aws:description>Monday</aws:description><aws:prediction>Areas of low clouds and fog in the morning then mostly sunny. Highs around 70 at the beaches to around 80 inland.</aws:prediction><aws:high units="&amp;deg;C">26</aws:high><aws:low units="&amp;deg;C">16</aws:low></aws:forecast><aws:forecast><aws:title alttitle="TUE">Tuesday</aws:title><aws:short-prediction>Mostly Sunny</aws:short-prediction><aws:image isNight="0" icon="cond026.gif">http://deskwx.weatherbug.com/images/Forecast/icons/cond026.gif</aws:image><aws:description>Tuesday</aws:description><aws:prediction>Night through morning low clouds and fog...otherwise mostly clear. Lows around 60. Highs in the mid to upper 60s at the beaches to the 70s inland.</aws:prediction><aws:high units="&amp;deg;C">25</aws:high><aws:low units="&amp;deg;C">16</aws:low></aws:forecast><aws:forecast><aws:title alttitle="WED">Wednesday</aws:title><aws:short-prediction>Mostly Sunny</aws:short-prediction><aws:image isNight="0" icon="cond026.gif">http://deskwx.weatherbug.com/images/Forecast/icons/cond026.gif</aws:image><aws:description>Wednesday</aws:description><aws:prediction>Night through morning low clouds and fog...otherwise mostly clear. Lows around 60. Highs in the mid to upper 60s at the beaches to the 70s inland.</aws:prediction><aws:high units="&amp;deg;C">24</aws:high><aws:low units="&amp;deg;C">16</aws:low></aws:forecast><aws:forecast><aws:title alttitle="THU">Thursday</aws:title><aws:short-prediction>Mostly Sunny</aws:short-prediction><aws:image isNight="0" icon="cond026.gif">http://deskwx.weatherbug.com/images/Forecast/icons/cond026.gif</aws:image><aws:description>Thursday</aws:description><aws:prediction>Night through morning low clouds and fog...otherwise mostly clear. Lows around 60. Highs in the mid to upper 60s at the beaches to the 70s inland.</aws:prediction><aws:high units="&amp;deg;C">24</aws:high><aws:low units="&amp;deg;C">--</aws:low></aws:forecast></aws:forecasts></aws:weather>
@@ -153,6 +153,22 @@ describe "Query::Coordinates" do
153
153
 
154
154
  end
155
155
 
156
+ describe "parsing" do
157
+
158
+ it "returns the latitude" do
159
+ Barometer::Query::Format::Coordinates.parse_latitude(@coordinates).should == "40.756054"
160
+ end
161
+
162
+ it "returns the longitude" do
163
+ Barometer::Query::Format::Coordinates.parse_longitude(@coordinates).should == "-73.986951"
164
+ end
165
+
166
+ it "returns nil when unknown" do
167
+ Barometer::Query::Format::Coordinates.parse_longitude(@short_zipcode).should be_nil
168
+ end
169
+
170
+ end
171
+
156
172
  end
157
173
 
158
174
  end
@@ -68,6 +68,15 @@ describe "Query::Format" do
68
68
  Barometer::Query::Format.convertable_formats.should == []
69
69
  end
70
70
 
71
+ it "stubs convert_query" do
72
+ Barometer::Query::Format.respond_to?(:convert_query).should be_true
73
+ end
74
+
75
+ it "normally does nothing when converting a query" do
76
+ text = "this is a query"
77
+ Barometer::Query::Format.convert_query(text).should == text
78
+ end
79
+
71
80
  end
72
81
 
73
82
  end
@@ -0,0 +1,215 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "Query::WoeID" do
4
+
5
+ before(:each) do
6
+ @short_zipcode = "90210"
7
+ @zipcode = @short_zipcode
8
+ @long_zipcode = "90210-5555"
9
+ @weather_id = "USGA0028"
10
+ @postal_code = "T5B 4M9"
11
+ @coordinates = "40.756054,-73.986951"
12
+ @geocode = "New York, NY"
13
+ @icao = "KSFO"
14
+ @woe_id = "615702"
15
+ end
16
+
17
+ describe "and class methods" do
18
+
19
+ it "returns a format" do
20
+ Barometer::Query::Format::WoeID.format.should == :woe_id
21
+ end
22
+
23
+ it "returns a country" do
24
+ Barometer::Query::Format::WoeID.country_code.should be_nil
25
+ end
26
+
27
+ it "returns a regex" do
28
+ Barometer::Query::Format::WoeID.regex.should_not be_nil
29
+ Barometer::Query::Format::WoeID.regex.is_a?(Regexp).should be_true
30
+ end
31
+
32
+ it "returns the convertable_formats" do
33
+ Query::Format::WoeID.convertable_formats.should_not be_nil
34
+ Query::Format::WoeID.convertable_formats.is_a?(Array).should be_true
35
+ Query::Format::WoeID.convertable_formats.include?(:short_zipcode).should be_true
36
+ Query::Format::WoeID.convertable_formats.include?(:zipcode).should be_true
37
+ Query::Format::WoeID.convertable_formats.include?(:postalcode).should be_true
38
+ Query::Format::WoeID.convertable_formats.include?(:weather_id).should be_true
39
+ Query::Format::WoeID.convertable_formats.include?(:coordinates).should be_true
40
+ Query::Format::WoeID.convertable_formats.include?(:icao).should be_true
41
+ Query::Format::WoeID.convertable_formats.include?(:geocode).should be_true
42
+ end
43
+
44
+ describe "is?," do
45
+
46
+ it "recognizes a valid 4 digit code format" do
47
+ @query = "8775"
48
+ Barometer::Query::Format::WoeID.is?(@query).should be_true
49
+ end
50
+
51
+ it "recognizes a valid 6 digit code format" do
52
+ @query = "615702"
53
+ Barometer::Query::Format::WoeID.is?(@query).should be_true
54
+ end
55
+
56
+ it "recognizes a valid 7 digit code format" do
57
+ @query = "2459115"
58
+ Barometer::Query::Format::WoeID.is?(@query).should be_true
59
+ end
60
+
61
+ it "recognizes a valid 5 digit code with a prepended 'w'" do
62
+ @query = "w90210"
63
+ Barometer::Query::Format::WoeID.is?(@query).should be_true
64
+ end
65
+
66
+ it "does not recognize a zip code" do
67
+ @query = "90210"
68
+ Barometer::Query::Format::WoeID.is?(@query).should be_false
69
+ end
70
+
71
+ it "recognizes non-valid format" do
72
+ @query = "USGA0028"
73
+ Barometer::Query::Format::WoeID.is?(@query).should be_false
74
+ end
75
+
76
+ end
77
+
78
+ it "converts the query" do
79
+ query_no_conversion = "2459115"
80
+ query = Barometer::Query.new(query_no_conversion)
81
+ query.q.should == query_no_conversion
82
+
83
+ query_with_conversion = "w90210"
84
+ query = Barometer::Query.new(query_with_conversion)
85
+ query.q.should_not == query_with_conversion
86
+ query.q.should == "90210"
87
+ end
88
+
89
+ describe "when reversing lookup" do
90
+
91
+ it "requires a Barometer::Query object" do
92
+ lambda { Barometer::Query::Format::WoeID.reverse }.should raise_error(ArgumentError)
93
+ lambda { Barometer::Query::Format::WoeID.reverse("invalid") }.should raise_error(ArgumentError)
94
+ query = Barometer::Query.new(@woe_id)
95
+ query.is_a?(Barometer::Query).should be_true
96
+ lambda { Barometer::Query::Format::WoeID.reverse(original_query) }.should_not raise_error(ArgumentError)
97
+ end
98
+
99
+ it "returns a Barometer::Query" do
100
+ query = Barometer::Query.new(@woe_id)
101
+ Barometer::Query::Format::WoeID.reverse(query).is_a?(Barometer::Query).should be_true
102
+ end
103
+
104
+ it "reverses a valid woe_id (US)" do
105
+ query = Barometer::Query.new(@woe_id)
106
+ new_query = Barometer::Query::Format::WoeID.reverse(query)
107
+ new_query.q.should == "Paris, France"
108
+ new_query.country_code.should be_nil
109
+ new_query.format.should == :geocode
110
+ new_query.geo.should be_nil
111
+ end
112
+
113
+ it "doesn't reverse an invalid weather_id" do
114
+ query = Barometer::Query.new(@zipcode)
115
+ Barometer::Query::Format::WoeID.reverse(query).should be_nil
116
+ end
117
+
118
+ end
119
+
120
+ describe "when converting using 'to'," do
121
+
122
+ before(:each) do
123
+ Barometer.google_geocode_key = KEY
124
+ end
125
+
126
+ it "requires a Barometer::Query object" do
127
+ lambda { Query::Format::WoeID.to }.should raise_error(ArgumentError)
128
+ lambda { Query::Format::WoeID.to("invalid") }.should raise_error(ArgumentError)
129
+ query = Barometer::Query.new(@woe_id)
130
+ query.is_a?(Barometer::Query).should be_true
131
+ lambda { Query::Format::WoeID.to(original_query) }.should_not raise_error(ArgumentError)
132
+ end
133
+
134
+ it "returns a Barometer::Query" do
135
+ query = Barometer::Query.new(@geocode)
136
+ Query::Format::WoeID.to(query).is_a?(Barometer::Query).should be_true
137
+ end
138
+
139
+ it "converts from short_zipcode" do
140
+ query = Barometer::Query.new(@short_zipcode)
141
+ query.format.should == :short_zipcode
142
+ new_query = Query::Format::WoeID.to(query)
143
+ new_query.q.should == "2363796"
144
+ new_query.country_code.should == "US"
145
+ new_query.format.should == :woe_id
146
+ new_query.geo.should_not be_nil
147
+ end
148
+
149
+ it "converts from zipcode" do
150
+ query = Barometer::Query.new(@zipcode)
151
+ query.format = :zipcode
152
+ query.format.should == :zipcode
153
+ new_query = Query::Format::WoeID.to(query)
154
+ new_query.q.should == "2363796"
155
+ new_query.country_code.should == "US"
156
+ new_query.format.should == :woe_id
157
+ new_query.geo.should_not be_nil
158
+ end
159
+
160
+ it "converts from postal code" do
161
+ query = Barometer::Query.new(@postal_code)
162
+ query.format = :postalcode
163
+ query.format.should == :postalcode
164
+ new_query = Query::Format::WoeID.to(query)
165
+ new_query.q.should == "8676"
166
+ new_query.country_code.should == "CA"
167
+ new_query.format.should == :woe_id
168
+ new_query.geo.should be_nil
169
+ end
170
+
171
+ it "converts from coordinates" do
172
+ query = Barometer::Query.new(@coordinates)
173
+ query.format.should == :coordinates
174
+ new_query = Query::Format::WoeID.to(query)
175
+ new_query.q.should == "2459115"
176
+ new_query.country_code.should be_nil
177
+ new_query.format.should == :woe_id
178
+ new_query.geo.should be_nil
179
+ end
180
+
181
+ it "converts from geocode" do
182
+ query = Barometer::Query.new(@geocode)
183
+ query.format.should == :geocode
184
+ new_query = Query::Format::WoeID.to(query)
185
+ new_query.q.should == "2459115"
186
+ new_query.country_code.should be_nil
187
+ new_query.format.should == :woe_id
188
+ new_query.geo.should be_nil
189
+ end
190
+
191
+ it "converts from weather_id" do
192
+ query = Barometer::Query.new(@weather_id)
193
+ query.format.should == :weather_id
194
+ new_query = Query::Format::WoeID.to(query)
195
+ new_query.q.should == "2357024"
196
+ new_query.country_code.should be_nil
197
+ new_query.format.should == :woe_id
198
+ new_query.geo.should be_nil
199
+ end
200
+
201
+ it "converts from icao" do
202
+ query = Barometer::Query.new(@icao)
203
+ query.format.should == :icao
204
+ new_query = Query::Format::WoeID.to(query)
205
+ new_query.q.should == "2451206"
206
+ new_query.country_code.should == "US"
207
+ new_query.format.should == :woe_id
208
+ new_query.geo.should_not be_nil
209
+ end
210
+
211
+ end
212
+
213
+ end
214
+
215
+ end