barometer 0.3.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. data/README.rdoc +78 -70
  2. data/VERSION.yml +2 -2
  3. data/bin/barometer +100 -37
  4. data/lib/barometer.rb +12 -8
  5. data/lib/barometer/base.rb +48 -20
  6. data/lib/barometer/data.rb +5 -1
  7. data/lib/barometer/data/current.rb +23 -15
  8. data/lib/barometer/data/distance.rb +15 -5
  9. data/lib/barometer/data/forecast.rb +23 -5
  10. data/lib/barometer/data/geo.rb +16 -54
  11. data/lib/barometer/data/local_datetime.rb +137 -0
  12. data/lib/barometer/data/local_time.rb +134 -0
  13. data/lib/barometer/data/location.rb +6 -1
  14. data/lib/barometer/data/measurement.rb +71 -42
  15. data/lib/barometer/data/night.rb +69 -0
  16. data/lib/barometer/data/pressure.rb +15 -5
  17. data/lib/barometer/data/speed.rb +16 -5
  18. data/lib/barometer/data/sun.rb +8 -20
  19. data/lib/barometer/data/temperature.rb +22 -9
  20. data/lib/barometer/data/units.rb +10 -19
  21. data/lib/barometer/data/zone.rb +135 -9
  22. data/lib/barometer/formats.rb +12 -0
  23. data/lib/barometer/formats/coordinates.rb +42 -0
  24. data/lib/barometer/formats/format.rb +46 -0
  25. data/lib/barometer/formats/geocode.rb +51 -0
  26. data/lib/barometer/formats/icao.rb +37 -0
  27. data/lib/barometer/formats/postalcode.rb +22 -0
  28. data/lib/barometer/formats/short_zipcode.rb +17 -0
  29. data/lib/barometer/formats/weather_id.rb +107 -0
  30. data/lib/barometer/formats/zipcode.rb +31 -0
  31. data/lib/barometer/query.rb +61 -232
  32. data/lib/barometer/services.rb +14 -4
  33. data/lib/barometer/translations/icao_country_codes.yml +9 -0
  34. data/lib/barometer/translations/weather_country_codes.yml +17 -0
  35. data/lib/barometer/weather.rb +51 -30
  36. data/lib/barometer/{services → weather_services}/google.rb +23 -26
  37. data/lib/barometer/weather_services/noaa.rb +6 -0
  38. data/lib/barometer/{services → weather_services}/service.rb +101 -92
  39. data/lib/barometer/weather_services/weather_bug.rb +6 -0
  40. data/lib/barometer/weather_services/weather_dot_com.rb +261 -0
  41. data/lib/barometer/{services → weather_services}/wunderground.rb +58 -76
  42. data/lib/barometer/{services → weather_services}/yahoo.rb +91 -121
  43. data/lib/barometer/web_services/geocode.rb +33 -0
  44. data/lib/barometer/web_services/weather_id.rb +37 -0
  45. data/lib/barometer/web_services/web_service.rb +32 -0
  46. data/lib/demometer/demometer.rb +31 -4
  47. data/lib/demometer/views/forecast.erb +20 -0
  48. data/lib/demometer/views/index.erb +10 -3
  49. data/lib/demometer/views/measurement.erb +8 -3
  50. data/lib/demometer/views/readme.erb +63 -24
  51. data/spec/barometer_spec.rb +18 -36
  52. data/spec/{data_current_spec.rb → data/current_spec.rb} +73 -49
  53. data/spec/{data_distance_spec.rb → data/distance_spec.rb} +30 -30
  54. data/spec/{data_forecast_spec.rb → data/forecast_spec.rb} +57 -15
  55. data/spec/data/geo_spec.rb +91 -0
  56. data/spec/data/local_datetime_spec.rb +269 -0
  57. data/spec/data/local_time_spec.rb +239 -0
  58. data/spec/{data_location_spec.rb → data/location_spec.rb} +12 -1
  59. data/spec/{data_measurement_spec.rb → data/measurement_spec.rb} +135 -66
  60. data/spec/data/night_measurement_spec.rb +136 -0
  61. data/spec/{data_pressure_spec.rb → data/pressure_spec.rb} +29 -29
  62. data/spec/{data_speed_spec.rb → data/speed_spec.rb} +30 -30
  63. data/spec/data/sun_spec.rb +49 -0
  64. data/spec/{data_temperature_spec.rb → data/temperature_spec.rb} +44 -44
  65. data/spec/{units_spec.rb → data/units_spec.rb} +6 -6
  66. data/spec/{data_zone_spec.rb → data/zone_spec.rb} +15 -15
  67. data/spec/fixtures/formats/weather_id/90210.xml +1 -0
  68. data/spec/fixtures/formats/weather_id/atlanta.xml +1 -0
  69. data/spec/fixtures/formats/weather_id/from_USGA0028.xml +1 -0
  70. data/spec/fixtures/formats/weather_id/new_york.xml +1 -0
  71. data/spec/fixtures/{geocode_40_73.xml → geocode/40_73.xml} +0 -0
  72. data/spec/fixtures/{geocode_90210.xml → geocode/90210.xml} +0 -0
  73. data/spec/fixtures/{geocode_T5B4M9.xml → geocode/T5B4M9.xml} +0 -0
  74. data/spec/fixtures/geocode/atlanta.xml +1 -0
  75. data/spec/fixtures/{geocode_calgary_ab.xml → geocode/calgary_ab.xml} +0 -0
  76. data/spec/fixtures/{geocode_ksfo.xml → geocode/ksfo.xml} +0 -0
  77. data/spec/fixtures/{geocode_newyork_ny.xml → geocode/newyork_ny.xml} +0 -0
  78. data/spec/fixtures/{google_calgary_ab.xml → services/google/calgary_ab.xml} +0 -0
  79. data/spec/fixtures/services/weather_dot_com/90210.xml +1 -0
  80. data/spec/fixtures/{current_calgary_ab.xml → services/wunderground/current_calgary_ab.xml} +0 -0
  81. data/spec/fixtures/{forecast_calgary_ab.xml → services/wunderground/forecast_calgary_ab.xml} +0 -0
  82. data/spec/fixtures/{yahoo_90210.xml → services/yahoo/90210.xml} +0 -0
  83. data/spec/formats/coordinates_spec.rb +158 -0
  84. data/spec/formats/format_spec.rb +73 -0
  85. data/spec/formats/geocode_spec.rb +179 -0
  86. data/spec/formats/icao_spec.rb +61 -0
  87. data/spec/formats/postalcode_spec.rb +59 -0
  88. data/spec/formats/short_zipcode_spec.rb +53 -0
  89. data/spec/formats/weather_id_spec.rb +191 -0
  90. data/spec/formats/zipcode_spec.rb +111 -0
  91. data/spec/query_spec.rb +261 -288
  92. data/spec/spec_helper.rb +128 -4
  93. data/spec/{service_google_spec.rb → weather_services/google_spec.rb} +46 -46
  94. data/spec/weather_services/services_spec.rb +1118 -0
  95. data/spec/weather_services/weather_dot_com_spec.rb +327 -0
  96. data/spec/weather_services/wunderground_spec.rb +332 -0
  97. data/spec/{service_yahoo_spec.rb → weather_services/yahoo_spec.rb} +65 -81
  98. data/spec/weather_spec.rb +73 -61
  99. data/spec/web_services/geocode_spec.rb +45 -0
  100. data/spec/web_services/web_services_spec.rb +26 -0
  101. metadata +88 -36
  102. data/lib/barometer/services/noaa.rb +0 -6
  103. data/lib/barometer/services/weather_bug.rb +0 -6
  104. data/lib/barometer/services/weather_dot_com.rb +0 -6
  105. data/spec/data_geo_spec.rb +0 -94
  106. data/spec/data_sun_spec.rb +0 -76
  107. data/spec/service_wunderground_spec.rb +0 -330
  108. data/spec/services_spec.rb +0 -1106
@@ -5,7 +5,7 @@ describe "Units" do
5
5
  describe "when initialized" do
6
6
 
7
7
  before(:each) do
8
- @units = Barometer::Units.new
8
+ @units = Data::Units.new
9
9
  end
10
10
 
11
11
  it "responds to metric, defaults to true" do
@@ -15,7 +15,7 @@ describe "Units" do
15
15
  it "allows metric to be set" do
16
16
  @units.metric.should be_true
17
17
 
18
- @units2 = Barometer::Units.new(false)
18
+ @units2 = Data::Units.new(false)
19
19
  @units2.metric.should be_false
20
20
  end
21
21
 
@@ -32,7 +32,7 @@ describe "Units" do
32
32
  describe "changing units" do
33
33
 
34
34
  before(:each) do
35
- @units = Barometer::Units.new
35
+ @units = Data::Units.new
36
36
  end
37
37
 
38
38
  it "indicates if metric?" do
@@ -62,7 +62,7 @@ describe "Units" do
62
62
 
63
63
  before(:each) do
64
64
  module Barometer
65
- class Units
65
+ class Data::Units
66
66
  attr_accessor :a, :b
67
67
  def metric_default=(value)
68
68
  self.a = value
@@ -72,8 +72,8 @@ describe "Units" do
72
72
  end
73
73
  end
74
74
  end
75
- @units_metric = Barometer::Units.new(true)
76
- @units_imperial = Barometer::Units.new(false)
75
+ @units_metric = Data::Units.new(true)
76
+ @units_imperial = Data::Units.new(false)
77
77
  @test_value_a = 5.5
78
78
  @test_value_b = 9.9
79
79
  end
@@ -1,17 +1,17 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Zone" do
3
+ describe "Data::Zone" do
4
4
 
5
5
  describe "and class methods" do
6
6
 
7
7
  it "responds to now and returns Time object" do
8
- Barometer::Zone.respond_to?("now").should be_true
9
- Barometer::Zone.now.is_a?(Time).should be_true
8
+ Data::Zone.respond_to?("now").should be_true
9
+ Data::Zone.now.is_a?(Time).should be_true
10
10
  end
11
11
 
12
12
  it "responds to today and returns Date object" do
13
- Barometer::Zone.respond_to?("today").should be_true
14
- Barometer::Zone.today.is_a?(Date).should be_true
13
+ Data::Zone.respond_to?("today").should be_true
14
+ Data::Zone.today.is_a?(Date).should be_true
15
15
  end
16
16
 
17
17
  end
@@ -21,7 +21,7 @@ describe "Zone" do
21
21
  before(:each) do
22
22
  @utc = Time.now.utc
23
23
  @timezone = "Europe/Paris"
24
- @zone = Barometer::Zone.new(@timezone)
24
+ @zone = Data::Zone.new(@timezone)
25
25
  end
26
26
 
27
27
  it "responds to timezone" do
@@ -30,26 +30,26 @@ describe "Zone" do
30
30
  end
31
31
 
32
32
  it "responds to tz" do
33
- lambda { Barometer::Zone.new("invalid timezone") }.should raise_error(TZInfo::InvalidTimezoneIdentifier)
33
+ lambda { Data::Zone.new("invalid timezone") }.should raise_error(TZInfo::InvalidTimezoneIdentifier)
34
34
 
35
- zone = Barometer::Zone.new(@timezone)
35
+ zone = Data::Zone.new(@timezone)
36
36
  zone.tz.should_not be_nil
37
37
  end
38
38
 
39
39
  it "responds to code" do
40
40
  @zone.respond_to?("code").should be_true
41
- zone = Barometer::Zone.new(@timezone)
41
+ zone = Data::Zone.new(@timezone)
42
42
  zone.tz = nil
43
43
  zone.tz.should be_nil
44
44
  zone.code.should == ""
45
45
 
46
- zone = Barometer::Zone.new(@timezone)
46
+ zone = Data::Zone.new(@timezone)
47
47
  zone.code.should == "CEST"
48
48
  end
49
49
 
50
50
  it "responds to dst?" do
51
51
  @zone.respond_to?("dst?").should be_true
52
- zone = Barometer::Zone.new(@timezone)
52
+ zone = Data::Zone.new(@timezone)
53
53
  zone.tz = nil
54
54
  zone.tz.should be_nil
55
55
  zone.dst?.should be_nil
@@ -66,11 +66,11 @@ describe "Zone" do
66
66
  end
67
67
 
68
68
  it "responds to now" do
69
- Barometer::Zone.respond_to?("now").should be_true
69
+ Data::Zone.respond_to?("now").should be_true
70
70
  end
71
71
 
72
72
  it "responds to today" do
73
- Barometer::Zone.respond_to?("today").should be_true
73
+ Data::Zone.respond_to?("today").should be_true
74
74
  end
75
75
 
76
76
  it "converts local_time to utc" do
@@ -104,7 +104,7 @@ describe "Zone" do
104
104
  # in two UTC times that are off by the same offset
105
105
  original_difference = local_offset - target_offset
106
106
 
107
- target_utc_time = Barometer::Zone.code_to_utc(target_time, target_zone)
107
+ target_utc_time = Data::Zone.code_to_utc(target_time, target_zone)
108
108
  local_utc_time = local_time.utc
109
109
 
110
110
  (target_utc_time - local_time.utc).to_i.should == original_difference.to_i
@@ -118,7 +118,7 @@ describe "Zone" do
118
118
  date = Date.parse(merge_date)
119
119
  time = Time.parse(merge_time)
120
120
 
121
- utc_time = Barometer::Zone.merge(merge_time, merge_date, merge_zonecode)
121
+ utc_time = Data::Zone.merge(merge_time, merge_date, merge_zonecode)
122
122
 
123
123
  utc_time.year.should == date.year
124
124
  utc_time.month.should == date.month
@@ -0,0 +1 @@
1
+ <?xml version='1.0' encoding='ISO-8859-1'?> <!-- This document is intended only for use by authorized licensees of The --> <!-- Weather Channel. Unauthorized use is prohibited. Copyright 1995-2009, --> <!-- The Weather Channel Interactive, Inc. All Rights Reserved. --> <search ver='3.0'> <loc id='USCA0090' type='1'> Beverly Hills, CA </loc> </search>
@@ -0,0 +1 @@
1
+ <?xml version='1.0' encoding='ISO-8859-1'?> <!-- This document is intended only for use by authorized licensees of The --> <!-- Weather Channel. Unauthorized use is prohibited. Copyright 1995-2009, --> <!-- The Weather Channel Interactive, Inc. All Rights Reserved. --> <search ver='3.0'> <loc id='USGA0028' type='1'> Atlanta, GA </loc> <loc id='USGA0029' type='1'> Atlanta/Fulton County Arpt, GA </loc> </search>
@@ -0,0 +1 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <rss version="2.0" xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"> <channel> <title>Yahoo! Weather - Atlanta, GA</title> <link>http://us.rd.yahoo.com/dailynews/rss/weather/Atlanta__GA/*http://weather.yahoo.com/forecast/USGA0028_f.html</link> <description>Yahoo! Weather for Atlanta, GA</description> <language>en-us</language> <lastBuildDate>Mon, 04 May 2009 2:52 am EDT</lastBuildDate> <ttl>60</ttl> <yweather:location city="Atlanta" region="GA" country="US"/> <yweather:units temperature="F" distance="mi" pressure="in" speed="mph"/> <yweather:wind chill="63" direction="230" speed="8" /> <yweather:atmosphere humidity="90" visibility="10" pressure="29.96" rising="0" /> <yweather:astronomy sunrise="6:47 am" sunset="8:23 pm"/> <image> <title>Yahoo! Weather</title> <width>142</width> <height>18</height> <link>http://weather.yahoo.com</link> <url>http://l.yimg.com/a/i/us/nws/th/main_142b.gif</url> </image> <item> <title>Conditions for Atlanta, GA at 2:52 am EDT</title> <geo:lat>33.75</geo:lat> <geo:long>-84.39</geo:long> <link>http://us.rd.yahoo.com/dailynews/rss/weather/Atlanta__GA/*http://weather.yahoo.com/forecast/USGA0028_f.html</link> <pubDate>Mon, 04 May 2009 2:52 am EDT</pubDate> <yweather:condition text="Mostly Cloudy" code="27" temp="63" date="Mon, 04 May 2009 2:52 am EDT" /> <description><![CDATA[ <img src="http://l.yimg.com/a/i/us/we/52/27.gif"/><br /> <b>Current Conditions:</b><br /> Mostly Cloudy, 63 F<BR /> <BR /><b>Forecast:</b><BR /> Mon - Strong Storms. High: 77 Low: 64<br /> Tue - Thunderstorms. High: 70 Low: 59<br /> <br /> <a href="http://us.rd.yahoo.com/dailynews/rss/weather/Atlanta__GA/*http://weather.yahoo.com/forecast/USGA0028_f.html">Full Forecast at Yahoo! Weather</a><BR/> (provided by The Weather Channel)<br/> ]]></description> <yweather:forecast day="Mon" date="4 May 2009" low="64" high="77" text="Strong Storms" code="3" /> <yweather:forecast day="Tue" date="5 May 2009" low="59" high="70" text="Thunderstorms" code="4" /> <guid isPermaLink="false">USGA0028_2009_05_04_2_52_EDT</guid> </item> </channel> </rss><!-- api4.weather.sp1.yahoo.com compressed/chunked Mon May 4 00:02:14 PDT 2009 -->
@@ -0,0 +1 @@
1
+ <?xml version='1.0' encoding='ISO-8859-1'?> <!-- This document is intended only for use by authorized licensees of The --> <!-- Weather Channel. Unauthorized use is prohibited. Copyright 1995-2009, --> <!-- The Weather Channel Interactive, Inc. All Rights Reserved. --> <search ver='3.0'> <loc id='USNY0996' type='1'> New York, NY </loc> <loc id='USNY0011' type='1'> Albany, NY </loc> <loc id='USNY0181' type='1'> Buffalo, NY </loc> <loc id='USNY1232' type='1'> Rochester, NY </loc> <loc id='USNY1434' type='1'> Syracuse, NY </loc> <loc id='USNY1010' type='1'> Niagara Falls, NY </loc> <loc id='USNY1630' type='1'> York, NY </loc> <loc id='USNY0997' type='1'> New York Mills, NY </loc> <loc id='USNY0819' type='1'> Little York, NY </loc> <loc id='USNY0998' type='1'> New York/Central Park, NY </loc> </search>
@@ -0,0 +1 @@
1
+ <?xml version="1.0" encoding="UTF-8" ?> <kml xmlns="http://earth.google.com/kml/2.0"><Response> <name>Atlanta, GA, US</name> <Status> <code>200</code> <request>geocode</request> </Status> <Placemark id="p1"> <address>Atlanta, GA, USA</address> <AddressDetails Accuracy="4" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>US</CountryNameCode><CountryName>USA</CountryName><AdministrativeArea><AdministrativeAreaName>GA</AdministrativeAreaName><Locality><LocalityName>Atlanta</LocalityName></Locality></AdministrativeArea></Country></AddressDetails> <ExtendedData> <LatLonBox north="33.8869080" south="33.6478380" east="-84.2894180" west="-84.5466630" /> </ExtendedData> <Point><coordinates>-84.3896630,33.7544870,0</coordinates></Point> </Placemark> </Response></kml>
@@ -0,0 +1 @@
1
+ <?xml version="1.0" encoding="ISO-8859-1"?> <!-- This document is intended only for use by authorized licensees of The --> <!-- Weather Channel. Unauthorized use is prohibited. Copyright 1995-2009, --> <!-- The Weather Channel Interactive, Inc. All Rights Reserved. --> <weather ver="2.0"> <head> <locale>en_US</locale> <form>MEDIUM</form> <ut>C</ut> <ud>km</ud> <us>km/h</us> <up>mb</up> <ur>mm</ur> </head> <loc id="90210"> <dnam>Beverly Hills, CA (90210)</dnam> <tm>1:26 AM</tm> <lat>34.10</lat> <lon>-118.41</lon> <sunr>6:01 AM</sunr> <suns>7:40 PM</suns> <zone>-7</zone> </loc> <lnks type="prmo"> <link pos="1"> <l>http://www.weather.com/allergies?par=xoap&amp;site=textlink&amp;cm_ven=XOAP&amp;cm_cat=TextLink&amp;cm_pla=Link1&amp;cm_ite=Allergies</l> <t>Local Pollen Reports</t> </link> <link pos="2"> <l>http://www.weather.com/flights?par=xoap&amp;site=textlink&amp;cm_ven=XOAP&amp;cm_cat=TextLink&amp;cm_pla=Link2&amp;cm_ite=BusinessTraveler</l> <t>Airport Conditions</t> </link> <link pos="3"> <l>http://www.weather.com/garden?par=xoap&amp;site=textlink&amp;cm_ven=XOAP&amp;cm_cat=TextLink&amp;cm_pla=Link3&amp;cm_ite=Garden</l> <t>Lawn and Garden Weather</t> </link> <link pos="4"> <l>http://www.weather.com/traffic?par=xoap&amp;site=textlink&amp;cm_ven=XOAP&amp;cm_cat=TextLink&amp;cm_pla=Link4&amp;cm_ite=Traffic</l> <t>Rush Hour Traffic</t> </link> </lnks> <cc> <lsup>5/4/09 12:51 AM PDT</lsup> <obst>Santa Monica, CA</obst> <tmp>16</tmp> <flik>16</flik> <t>Fair</t> <icon>33</icon> <bar> <r>1016.6</r> <d>rising</d> </bar> <wind> <s>5</s> <gust>N/A</gust> <d>80</d> <t>E</t> </wind> <hmid>75</hmid> <vis>16.1</vis> <uv> <i>0</i> <t>Low</t> </uv> <dewp>12</dewp> <moon> <icon>9</icon> <t>Waxing Gibbous</t> </moon> </cc> <dayf> <lsup>5/4/09 12:25 AM PDT</lsup> <day d="0" t="Sunday" dt="May 3"> <hi>N/A</hi> <low>14</low> <sunr>6:02 AM</sunr> <suns>7:40 PM</suns> <part p="d"> <icon>30</icon> <t>Partly Cloudy</t> <wind> <s>16</s> <gust>N/A</gust> <d>288</d> <t>WNW</t> </wind> <bt>P Cloudy</bt> <ppcp>10</ppcp> <hmid>65</hmid> </part> <part p="n"> <icon>29</icon> <t>Partly Cloudy</t> <wind> <s>14</s> <gust>N/A</gust> <d>335</d> <t>NNW</t> </wind> <bt>P Cloudy</bt> <ppcp>10</ppcp> <hmid>71</hmid> </part> </day> <day d="1" t="Monday" dt="May 4"> <hi>25</hi> <low>14</low> <sunr>6:01 AM</sunr> <suns>7:40 PM</suns> <part p="d"> <icon>30</icon> <t>Partly Cloudy</t> <wind> <s>18</s> <gust>N/A</gust> <d>260</d> <t>W</t> </wind> <bt>P Cloudy</bt> <ppcp>10</ppcp> <hmid>53</hmid> </part> <part p="n"> <icon>29</icon> <t>Partly Cloudy</t> <wind> <s>13</s> <gust>N/A</gust> <d>334</d> <t>NNW</t> </wind> <bt>P Cloudy</bt> <ppcp>0</ppcp> <hmid>67</hmid> </part> </day> <day d="2" t="Tuesday" dt="May 5"> <hi>26</hi> <low>16</low> <sunr>6:00 AM</sunr> <suns>7:41 PM</suns> <part p="d"> <icon>30</icon> <t>Partly Cloudy</t> <wind> <s>19</s> <gust>N/A</gust> <d>279</d> <t>W</t> </wind> <bt>P Cloudy</bt> <ppcp>0</ppcp> <hmid>53</hmid> </part> <part p="n"> <icon>33</icon> <t>Mostly Clear</t> <wind> <s>10</s> <gust>N/A</gust> <d>313</d> <t>NW</t> </wind> <bt>M Clear</bt> <ppcp>0</ppcp> <hmid>63</hmid> </part> </day> <day d="3" t="Wednesday" dt="May 6"> <hi>27</hi> <low>16</low> <sunr>5:59 AM</sunr> <suns>7:42 PM</suns> <part p="d"> <icon>34</icon> <t>Mostly Sunny</t> <wind> <s>13</s> <gust>N/A</gust> <d>286</d> <t>WNW</t> </wind> <bt>M Sunny</bt> <ppcp>0</ppcp> <hmid>55</hmid> </part> <part p="n"> <icon>31</icon> <t>Clear</t> <wind> <s>8</s> <gust>N/A</gust> <d>313</d> <t>NW</t> </wind> <bt>Clear</bt> <ppcp>0</ppcp> <hmid>56</hmid> </part> </day> <day d="4" t="Thursday" dt="May 7"> <hi>26</hi> <low>16</low> <sunr>5:58 AM</sunr> <suns>7:43 PM</suns> <part p="d"> <icon>32</icon> <t>Sunny</t> <wind> <s>14</s> <gust>N/A</gust> <d>318</d> <t>NW</t> </wind> <bt>Sunny</bt> <ppcp>0</ppcp> <hmid>49</hmid> </part> <part p="n"> <icon>31</icon> <t>Clear</t> <wind> <s>6</s> <gust>N/A</gust> <d>13</d> <t>NNE</t> </wind> <bt>Clear</bt> <ppcp>0</ppcp> <hmid>50</hmid> </part> </day> </dayf> </weather>
@@ -0,0 +1,158 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Query::Coordinates" 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
+ end
15
+
16
+ describe "and class methods" do
17
+
18
+ it "returns a format" do
19
+ Query::Format::Coordinates.format.should == :coordinates
20
+ end
21
+
22
+ it "returns a country" do
23
+ Query::Format::Coordinates.country_code.should be_nil
24
+ end
25
+
26
+ it "returns a regex" do
27
+ Query::Format::Coordinates.regex.should_not be_nil
28
+ Query::Format::Coordinates.regex.is_a?(Regexp).should be_true
29
+ end
30
+
31
+ it "returns the convertable_formats" do
32
+ Query::Format::Coordinates.convertable_formats.should_not be_nil
33
+ Query::Format::Coordinates.convertable_formats.is_a?(Array).should be_true
34
+ Query::Format::Coordinates.convertable_formats.include?(:short_zipcode).should be_true
35
+ Query::Format::Coordinates.convertable_formats.include?(:zipcode).should be_true
36
+ Query::Format::Coordinates.convertable_formats.include?(:postalcode).should be_true
37
+ Query::Format::Coordinates.convertable_formats.include?(:weather_id).should be_true
38
+ Query::Format::Coordinates.convertable_formats.include?(:coordinates).should be_true
39
+ Query::Format::Coordinates.convertable_formats.include?(:icao).should be_true
40
+ Query::Format::Coordinates.convertable_formats.include?(:geocode).should be_true
41
+ end
42
+
43
+ describe "is?," do
44
+
45
+ before(:each) do
46
+ @valid = "40.756054,-73.986951"
47
+ @invalid = "invalid"
48
+ end
49
+
50
+ it "recognizes a valid format" do
51
+ Query::Format::Coordinates.is?(@valid).should be_true
52
+ end
53
+
54
+ it "recognizes non-valid format" do
55
+ Query::Format::Coordinates.is?(@invalid).should be_false
56
+ end
57
+
58
+ end
59
+
60
+ describe "when converting using 'to'," do
61
+
62
+ it "requires a Query::Format object" do
63
+ lambda { Query::Format::Coordinates.to }.should raise_error(ArgumentError)
64
+ lambda { Query::Format::Coordinates.to("invalid") }.should raise_error(ArgumentError)
65
+ query = Barometer::Query.new(@zipcode)
66
+ query.is_a?(Barometer::Query).should be_true
67
+ lambda { Query::Format::Coordinates.to(original_query) }.should_not raise_error(ArgumentError)
68
+ end
69
+
70
+ it "returns a Barometer::Query" do
71
+ query = Barometer::Query.new(@short_zipcode)
72
+ Query::Format::Coordinates.to(query).is_a?(Barometer::Query).should be_true
73
+ end
74
+
75
+ it "converts from short_zipcode" do
76
+ query = Barometer::Query.new(@short_zipcode)
77
+ query.format.should == :short_zipcode
78
+ new_query = Query::Format::Coordinates.to(query)
79
+ new_query.q.should == "34.1030032,-118.4104684"
80
+ new_query.country_code.should == "US"
81
+ new_query.format.should == :coordinates
82
+ new_query.geo.should_not be_nil
83
+ end
84
+
85
+ it "converts from zipcode" do
86
+ query = Barometer::Query.new(@zipcode)
87
+ query.format = :zipcode
88
+ query.format.should == :zipcode
89
+ new_query = Query::Format::Coordinates.to(query)
90
+ new_query.q.should == "34.1030032,-118.4104684"
91
+ new_query.country_code.should == "US"
92
+ new_query.format.should == :coordinates
93
+ new_query.geo.should_not be_nil
94
+ end
95
+
96
+ it "converts from weather_id" do
97
+ query = Barometer::Query.new(@weather_id)
98
+ query.format.should == :weather_id
99
+ new_query = Query::Format::Coordinates.to(query)
100
+ new_query.q.should == "33.754487,-84.389663"
101
+ new_query.country_code.should == "US"
102
+ new_query.format.should == :coordinates
103
+ new_query.geo.should_not be_nil
104
+ end
105
+
106
+ it "converts from geocode" do
107
+ query = Barometer::Query.new(@geocode)
108
+ query.format.should == :geocode
109
+ new_query = Query::Format::Coordinates.to(query)
110
+ new_query.q.should == "40.756054,-73.986951"
111
+ new_query.country_code.should == "US"
112
+ new_query.format.should == :coordinates
113
+ new_query.geo.should_not be_nil
114
+ end
115
+
116
+ it "converts from postal_code" do
117
+ query = Barometer::Query.new(@postal_code)
118
+ query.format.should == :postalcode
119
+ new_query = Query::Format::Coordinates.to(query)
120
+ new_query.q.should == "53.570447,-113.456083"
121
+ new_query.country_code.should == "CA"
122
+ new_query.format.should == :coordinates
123
+ new_query.geo.should_not be_nil
124
+ end
125
+
126
+ it "converts from icao" do
127
+ query = Barometer::Query.new(@icao)
128
+ query.format.should == :icao
129
+ new_query = Query::Format::Coordinates.to(query)
130
+ new_query.q.should == "37.615223,-122.389979"
131
+ new_query.country_code.should == "US"
132
+ new_query.format.should == :coordinates
133
+ new_query.geo.should_not be_nil
134
+ end
135
+
136
+ it "returns nil for other formats" do
137
+ query = Barometer::Query.new(@coordinates)
138
+ query.format.should == :coordinates
139
+ new_query = Query::Format::Coordinates.to(query)
140
+ new_query.q.should == "40.756201,-73.986513"
141
+ new_query.country_code.should == "US"
142
+ new_query.format.should == :coordinates
143
+ new_query.geo.should_not be_nil
144
+ end
145
+
146
+ it "skips conversion when no API key" do
147
+ Barometer.google_geocode_key = nil
148
+ Barometer.google_geocode_key.should be_nil
149
+ query = Barometer::Query.new(@short_zipcode)
150
+ Query::Format::Coordinates.to(query).q.should be_nil
151
+ Barometer.google_geocode_key = KEY
152
+ end
153
+
154
+ end
155
+
156
+ end
157
+
158
+ end
@@ -0,0 +1,73 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Query::Format" do
4
+
5
+ describe "and class methods" do
6
+
7
+ describe "is?," do
8
+
9
+ it "requires a String" do
10
+ invalid = 1
11
+ lambda { Barometer::Query::Format.is?(invalid) }.should raise_error(ArgumentError)
12
+
13
+ valid = "string"
14
+ valid.is_a?(String).should be_true
15
+ lambda { Barometer::Query::Format.is?(valid) }.should_not raise_error(ArgumentError)
16
+ end
17
+
18
+ it "calls a stubbed undefined method" do
19
+ lambda { Barometer::Query::Format.is?("valid") }.should raise_error(NotImplementedError)
20
+ end
21
+
22
+ end
23
+
24
+ describe "converts?," do
25
+
26
+ it "requires a Query object" do
27
+ invalid = 1
28
+ Barometer::Query::Format.converts?(invalid).should be_false
29
+
30
+ valid = Barometer::Query.new
31
+ valid.is_a?(Barometer::Query).should be_true
32
+ lambda { Barometer::Query::Format.converts?(valid) }.should_not raise_error(ArgumentError)
33
+ end
34
+
35
+ it "returns false" do
36
+ valid = Barometer::Query.new
37
+ Barometer::Query::Format.converts?(valid).should be_false
38
+ end
39
+
40
+ end
41
+
42
+ it "detects a Query object" do
43
+ invalid = 1
44
+ Barometer::Query::Format.is_a_query?.should be_false
45
+ Barometer::Query::Format.is_a_query?(invalid).should be_false
46
+ valid = Barometer::Query.new
47
+ valid.is_a?(Barometer::Query).should be_true
48
+ Barometer::Query::Format.is_a_query?(valid).should be_true
49
+ end
50
+
51
+ it "stubs regex" do
52
+ lambda { Barometer::Query::Format.regex }.should raise_error(NotImplementedError)
53
+ end
54
+
55
+ it "stubs format" do
56
+ lambda { Barometer::Query::Format.format }.should raise_error(NotImplementedError)
57
+ end
58
+
59
+ it "stubs to" do
60
+ Barometer::Query::Format.to.should be_nil
61
+ end
62
+
63
+ it "stubs country_code" do
64
+ Barometer::Query::Format.country_code.should be_nil
65
+ end
66
+
67
+ it "stubs convertable_formats" do
68
+ Barometer::Query::Format.convertable_formats.should == []
69
+ end
70
+
71
+ end
72
+
73
+ end
@@ -0,0 +1,179 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Query::Geocode" 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
+ end
15
+
16
+ describe "and class methods" do
17
+
18
+ it "returns a format" do
19
+ Query::Format::Geocode.format.should == :geocode
20
+ end
21
+
22
+ it "returns a country" do
23
+ Query::Format::Geocode.country_code.should be_nil
24
+ end
25
+
26
+ it "returns the convertable_formats" do
27
+ Query::Format::Geocode.convertable_formats.should_not be_nil
28
+ Query::Format::Geocode.convertable_formats.is_a?(Array).should be_true
29
+ Query::Format::Geocode.convertable_formats.include?(:short_zipcode).should be_true
30
+ Query::Format::Geocode.convertable_formats.include?(:zipcode).should be_true
31
+ Query::Format::Geocode.convertable_formats.include?(:coordinates).should be_true
32
+ Query::Format::Geocode.convertable_formats.include?(:weather_id).should be_true
33
+ Query::Format::Geocode.convertable_formats.include?(:icao).should be_true
34
+ end
35
+
36
+ describe "is?," do
37
+
38
+ before(:each) do
39
+ @valid = "New York, NY"
40
+ end
41
+
42
+ it "recognizes a valid format" do
43
+ Query::Format::Geocode.is?(@valid).should be_true
44
+ Query::Format::Geocode.is?.should be_false
45
+ end
46
+
47
+ end
48
+
49
+ describe "when converting using 'to'," do
50
+
51
+ before(:each) do
52
+ Barometer.force_geocode = false
53
+ end
54
+
55
+ it "requires a Barometer::Query object" do
56
+ lambda { Query::Format::Geocode.to }.should raise_error(ArgumentError)
57
+ lambda { Query::Format::Geocode.to("invalid") }.should raise_error(ArgumentError)
58
+ query = Barometer::Query.new(@zipcode)
59
+ query.is_a?(Barometer::Query).should be_true
60
+ lambda { Query::Format::Geocode.to(query) }.should_not raise_error(ArgumentError)
61
+ end
62
+
63
+ it "returns a Barometer::Query" do
64
+ query = Barometer::Query.new(@short_zipcode)
65
+ Query::Format::Geocode.to(query).is_a?(Barometer::Query).should be_true
66
+ end
67
+
68
+ it "converts from short_zipcode" do
69
+ query = Barometer::Query.new(@short_zipcode)
70
+ query.format.should == :short_zipcode
71
+ new_query = Query::Format::Geocode.to(query)
72
+ new_query.q.should == "Beverly Hills, CA, USA"
73
+ new_query.country_code.should == "US"
74
+ new_query.format.should == :geocode
75
+ new_query.geo.should_not be_nil
76
+ end
77
+
78
+ it "converts from zipcode" do
79
+ query = Barometer::Query.new(@zipcode)
80
+ query.format = :zipcode
81
+ query.format.should == :zipcode
82
+ new_query = Query::Format::Geocode.to(query)
83
+ new_query.q.should == "Beverly Hills, CA, USA"
84
+ new_query.country_code.should == "US"
85
+ new_query.format.should == :geocode
86
+ new_query.geo.should_not be_nil
87
+ end
88
+
89
+ it "converts from weather_id" do
90
+ query = Barometer::Query.new(@weather_id)
91
+ query.format.should == :weather_id
92
+ new_query = Query::Format::Geocode.to(query)
93
+ new_query.q.should == "Atlanta, GA, US"
94
+ new_query.country_code.should be_nil
95
+ new_query.format.should == :geocode
96
+ new_query.geo.should be_nil
97
+ end
98
+
99
+ it "converts from coordinates" do
100
+ query = Barometer::Query.new(@coordinates)
101
+ query.format.should == :coordinates
102
+ new_query = Query::Format::Geocode.to(query)
103
+ new_query.q.should == "New York, NY, USA"
104
+ new_query.country_code.should == "US"
105
+ new_query.format.should == :geocode
106
+ new_query.geo.should_not be_nil
107
+ end
108
+
109
+ it "converts from icao" do
110
+ query = Barometer::Query.new(@icao)
111
+ query.format.should == :icao
112
+ new_query = Query::Format::Geocode.to(query)
113
+ new_query.q.should == "San Francisco Airport, USA"
114
+ new_query.country_code.should == "US"
115
+ new_query.format.should == :geocode
116
+ new_query.geo.should_not be_nil
117
+ end
118
+
119
+ it "does not convert postalcode" do
120
+ query = Barometer::Query.new(@postal_code)
121
+ query.format.should == :postalcode
122
+ new_query = Query::Format::Geocode.to(query)
123
+ new_query.should be_nil
124
+ end
125
+
126
+ it "leaves geocode untouched" do
127
+ query = Barometer::Query.new(@geocode)
128
+ query.format.should == :geocode
129
+ new_query = Query::Format::Geocode.to(query)
130
+ new_query.q.should == "New York, NY"
131
+ new_query.country_code.should be_nil
132
+ new_query.format.should == :geocode
133
+ new_query.geo.should be_nil
134
+ end
135
+
136
+ it "skips conversion when no API key" do
137
+ Barometer.google_geocode_key = nil
138
+ Barometer.google_geocode_key.should be_nil
139
+ query = Barometer::Query.new(@coordinates)
140
+ Query::Format::Geocode.to(query).q.should be_nil
141
+ Barometer.google_geocode_key = KEY
142
+ end
143
+
144
+ end
145
+
146
+ describe "when geocoding" do
147
+
148
+ it "requires a Barometer::Query object" do
149
+ lambda { Query::Format::Geocode.geocode }.should raise_error(ArgumentError)
150
+ lambda { Query::Format::Geocode.geocode("invalid") }.should raise_error(ArgumentError)
151
+ query = Barometer::Query.new(@zipcode)
152
+ query.is_a?(Barometer::Query).should be_true
153
+ lambda { Query::Format::Geocode.geocode(original_query) }.should_not raise_error(ArgumentError)
154
+ end
155
+
156
+ it "returns a Barometer::Query" do
157
+ query = Barometer::Query.new(@short_zipcode)
158
+ Query::Format::Geocode.geocode(query).is_a?(Barometer::Query).should be_true
159
+ end
160
+
161
+ it "converts from short_zipcode" do
162
+ query = Barometer::Query.new(@short_zipcode)
163
+ query.format.should == :short_zipcode
164
+ new_query = Query::Format::Geocode.geocode(query)
165
+ new_query.q.should == "Beverly Hills, CA, USA"
166
+ new_query.country_code.should == "US"
167
+ new_query.format.should == :geocode
168
+ new_query.geo.should_not be_nil
169
+ end
170
+
171
+ end
172
+
173
+ it "doesn't define a regex" do
174
+ lambda { Query::Format::Geocode.regex }.should raise_error(NotImplementedError)
175
+ end
176
+
177
+ end
178
+
179
+ end