barometer 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.rdoc +266 -0
- data/VERSION.yml +4 -0
- data/bin/barometer +63 -0
- data/lib/barometer.rb +52 -0
- data/lib/barometer/base.rb +52 -0
- data/lib/barometer/data.rb +15 -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/extensions/graticule.rb +50 -0
- data/lib/barometer/extensions/httparty.rb +21 -0
- data/lib/barometer/query.rb +228 -0
- data/lib/barometer/services.rb +6 -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/weather.rb +187 -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,133 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Zone" do
|
4
|
+
|
5
|
+
describe "and class methods" do
|
6
|
+
|
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
|
10
|
+
end
|
11
|
+
|
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
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "when initialized" do
|
20
|
+
|
21
|
+
before(:each) do
|
22
|
+
@utc = Time.now.utc
|
23
|
+
@timezone = "Europe/Paris"
|
24
|
+
@zone = Barometer::Zone.new(@timezone)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "responds to timezone" do
|
28
|
+
@zone.timezone.should_not be_nil
|
29
|
+
@zone.timezone.should == @timezone
|
30
|
+
end
|
31
|
+
|
32
|
+
it "responds to tz" do
|
33
|
+
lambda { Barometer::Zone.new("invalid timezone") }.should raise_error(TZInfo::InvalidTimezoneIdentifier)
|
34
|
+
|
35
|
+
zone = Barometer::Zone.new(@timezone)
|
36
|
+
zone.tz.should_not be_nil
|
37
|
+
end
|
38
|
+
|
39
|
+
it "responds to code" do
|
40
|
+
@zone.respond_to?("code").should be_true
|
41
|
+
zone = Barometer::Zone.new(@timezone)
|
42
|
+
zone.tz = nil
|
43
|
+
zone.tz.should be_nil
|
44
|
+
zone.code.should == ""
|
45
|
+
|
46
|
+
zone = Barometer::Zone.new(@timezone)
|
47
|
+
zone.code.should == "CEST"
|
48
|
+
end
|
49
|
+
|
50
|
+
it "responds to dst?" do
|
51
|
+
@zone.respond_to?("dst?").should be_true
|
52
|
+
zone = Barometer::Zone.new(@timezone)
|
53
|
+
zone.tz = nil
|
54
|
+
zone.tz.should be_nil
|
55
|
+
zone.dst?.should be_nil
|
56
|
+
end
|
57
|
+
|
58
|
+
it "responds to now" do
|
59
|
+
@zone.respond_to?("now").should be_true
|
60
|
+
@zone.now.is_a?(Time).should be_true
|
61
|
+
end
|
62
|
+
|
63
|
+
it "responds to today" do
|
64
|
+
@zone.respond_to?("today").should be_true
|
65
|
+
@zone.today.is_a?(Date).should be_true
|
66
|
+
end
|
67
|
+
|
68
|
+
it "responds to now" do
|
69
|
+
Barometer::Zone.respond_to?("now").should be_true
|
70
|
+
end
|
71
|
+
|
72
|
+
it "responds to today" do
|
73
|
+
Barometer::Zone.respond_to?("today").should be_true
|
74
|
+
end
|
75
|
+
|
76
|
+
it "converts local_time to utc" do
|
77
|
+
local_time = Time.now.utc
|
78
|
+
utc_time = @zone.local_to_utc(local_time)
|
79
|
+
|
80
|
+
offset = @zone.tz.period_for_utc(local_time).utc_total_offset
|
81
|
+
utc_time.should == (local_time - offset)
|
82
|
+
end
|
83
|
+
|
84
|
+
it "converts utc to local_time" do
|
85
|
+
utc_time = Time.now.utc
|
86
|
+
local_time = @zone.utc_to_local(utc_time)
|
87
|
+
|
88
|
+
offset = @zone.tz.period_for_utc(local_time).utc_total_offset
|
89
|
+
utc_time.should == (local_time - offset)
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "when manipulating times" do
|
95
|
+
|
96
|
+
it "converts a time to utc based on TimeZone Short Code" do
|
97
|
+
target_zone = "PDT"
|
98
|
+
target_offset = Time.zone_offset("PDT")
|
99
|
+
target_time = Time.now
|
100
|
+
local_time = target_time
|
101
|
+
local_offset = Time.zone_offset(local_time.zone)
|
102
|
+
|
103
|
+
# converting two times (ie 6am PDT and 6am MDT) to UTC should result
|
104
|
+
# in two UTC times that are off by the same offset
|
105
|
+
original_difference = local_offset - target_offset
|
106
|
+
|
107
|
+
target_utc_time = Barometer::Zone.code_to_utc(target_time, target_zone)
|
108
|
+
local_utc_time = local_time.utc
|
109
|
+
|
110
|
+
(target_utc_time - local_time.utc).to_i.should == original_difference.to_i
|
111
|
+
end
|
112
|
+
|
113
|
+
it "merges a date and a time to one utc time (biased by TimeZone Short Code)" do
|
114
|
+
merge_date = "1 March 1990"
|
115
|
+
merge_time = "5:35 am"
|
116
|
+
merge_zonecode = "UTC"
|
117
|
+
|
118
|
+
date = Date.parse(merge_date)
|
119
|
+
time = Time.parse(merge_time)
|
120
|
+
|
121
|
+
utc_time = Barometer::Zone.merge(merge_time, merge_date, merge_zonecode)
|
122
|
+
|
123
|
+
utc_time.year.should == date.year
|
124
|
+
utc_time.month.should == date.month
|
125
|
+
utc_time.day.should == date.day
|
126
|
+
utc_time.hour.should == time.hour
|
127
|
+
utc_time.min.should == time.min
|
128
|
+
utc_time.sec.should == time.sec
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<current_observation> <credit>Weather Underground NOAA Weather Station</credit> <credit_URL>http://wunderground.com/</credit_URL> <image> <url>http://icons.wunderground.com/graphics/wu2/logo_130x80.png</url> <title>Weather Underground</title> <link>http://wunderground.com/</link> </image> <display_location> <full>Calgary, Alberta</full> <city>Calgary</city> <state>AB</state> <state_name>Alberta</state_name> <country>CA</country> <zip>00000</zip> <latitude>51.11999893</latitude> <longitude>-114.01999664</longitude> <elevation> ft</elevation> </display_location> <observation_location> <full>Calgary, </full> <city>Calgary</city> <state></state> <country>CA</country> <latitude>51.11999893</latitude> <longitude>-114.01999664</longitude> <elevation>3556 ft</elevation> </observation_location> <station_id>CYYC</station_id> <observation_time>Last Updated on April 23, 4:00 PM MDT</observation_time> <observation_time_rfc822>Thu, 23 April 2009 22:00:0 GMT</observation_time_rfc822> <weather>Scattered Clouds</weather> <temperature_string>28 F (-2 C)</temperature_string> <temp_f>28</temp_f> <temp_c>-2</temp_c> <relative_humidity>51%</relative_humidity> <wind_string>From the NNW at 13 MPH </wind_string> <wind_dir>NNW</wind_dir> <wind_degrees>340</wind_degrees> <wind_mph>13</wind_mph> <wind_gust_mph></wind_gust_mph> <pressure_string>30.11" (1020 mb)</pressure_string> <pressure_mb>1020</pressure_mb> <pressure_in>30.11</pressure_in> <dewpoint_string>12 F (-11 C)</dewpoint_string> <dewpoint_f>12</dewpoint_f> <dewpoint_c>-11</dewpoint_c> <heat_index_string>NA</heat_index_string> <heat_index_f>NA</heat_index_f> <heat_index_c>NA</heat_index_c> <windchill_string>18 F (-8 C)</windchill_string> <windchill_f>18</windchill_f> <windchill_c>-8</windchill_c> <visibility_mi>20.0</visibility_mi> <visibility_km>32.2</visibility_km> <icon_url_base>http://icons.wunderground.com/graphics/conds/</icon_url_base> <icon_url_name>.GIF</icon_url_name> <icon>partlycloudy</icon> <forecast_url>http://www.wunderground.com/global/stations/71877.html</forecast_url> <history_url>http://www.wunderground.com/history/airport/CYYC/2009/4/23/DailyHistory.html</history_url> <ob_url>http://www.wunderground.com/cgi-bin/findweather/getForecast?query=51.11999893,-114.01999664</ob_url> </current_observation> <!-- 0.050:0 -->
|
@@ -0,0 +1 @@
|
|
1
|
+
<forecast> <txt_forecast> <date></date> <number></number> <forecastday> <period>1</period> <icon>chancesnow</icon> <title>April 23, 2009</title> <fcttext>Chance of Snow. High 0&deg;C (32&deg;F). Winds 21 kph NNW </fcttext> <pop>20</pop> </forecastday> <forecastday> <period>2</period> <icon>chancesnow</icon> <title>April 24, 2009</title> <fcttext>Chance of Snow. High 2&deg;C (35&deg;F). Winds 10 kph NE </fcttext> <pop>20</pop> </forecastday> </txt_forecast> <simpleforecast> <forecastday> <period>1</period> <date> <epoch>1240531200</epoch> <pretty_short>6:00 PM MDT</pretty_short> <pretty>6:00 PM MDT on April 23, 2009</pretty> <day>23</day> <month>4</month> <year>2009</year> <yday>112</yday> <hour>18</hour> <min>00</min> <sec>0</sec> <isdst>1</isdst> <monthname>April</monthname> <weekday_short></weekday_short> <weekday>Thursday</weekday> <ampm>PM</ampm> <tz_short>MDT</tz_short> <tz_long>America/Edmonton</tz_long> </date> <high> <fahrenheit>32</fahrenheit> <celsius>0</celsius> </high> <low> <fahrenheit>22</fahrenheit> <celsius>-5</celsius> </low> <conditions>Chance of Snow</conditions> <icon>chancesnow</icon> <skyicon>cloudy</skyicon> <pop>20</pop> </forecastday> <forecastday> <period>2</period> <date> <epoch>1240617600</epoch> <pretty_short>6:00 PM MDT</pretty_short> <pretty>6:00 PM MDT on April 24, 2009</pretty> <day>24</day> <month>4</month> <year>2009</year> <yday>113</yday> <hour>18</hour> <min>00</min> <sec>0</sec> <isdst>1</isdst> <monthname>April</monthname> <weekday_short></weekday_short> <weekday>Friday</weekday> <ampm>PM</ampm> <tz_short>MDT</tz_short> <tz_long>America/Edmonton</tz_long> </date> <high> <fahrenheit>35</fahrenheit> <celsius>2</celsius> </high> <low> <fahrenheit>28</fahrenheit> <celsius>-2</celsius> </low> <conditions>Chance of Snow</conditions> <icon>chancesnow</icon> <skyicon>partlycloudy</skyicon> <pop>20</pop> </forecastday> <forecastday> <period>3</period> <date> <epoch>1240704000</epoch> <pretty_short>6:00 PM MDT</pretty_short> <pretty>6:00 PM MDT on April 25, 2009</pretty> <day>25</day> <month>4</month> <year>2009</year> <yday>114</yday> <hour>18</hour> <min>00</min> <sec>0</sec> <isdst>1</isdst> <monthname>April</monthname> <weekday_short></weekday_short> <weekday>Saturday</weekday> <ampm>PM</ampm> <tz_short>MDT</tz_short> <tz_long>America/Edmonton</tz_long> </date> <high> <fahrenheit>44</fahrenheit> <celsius>7</celsius> </high> <low> <fahrenheit>30</fahrenheit> <celsius>-1</celsius> </low> <conditions>Chance of Snow</conditions> <icon>chancesnow</icon> <skyicon>cloudy</skyicon> <pop>40</pop> </forecastday> <forecastday> <period>4</period> <date> <epoch>1240790400</epoch> <pretty_short>6:00 PM MDT</pretty_short> <pretty>6:00 PM MDT on April 26, 2009</pretty> <day>26</day> <month>4</month> <year>2009</year> <yday>115</yday> <hour>18</hour> <min>00</min> <sec>0</sec> <isdst>1</isdst> <monthname>April</monthname> <weekday_short></weekday_short> <weekday>Sunday</weekday> <ampm>PM</ampm> <tz_short>MDT</tz_short> <tz_long>America/Edmonton</tz_long> </date> <high> <fahrenheit>33</fahrenheit> <celsius>1</celsius> </high> <low> <fahrenheit>22</fahrenheit> <celsius>-5</celsius> </low> <conditions>Chance of Snow</conditions> <icon>chancesnow</icon> <skyicon>cloudy</skyicon> <pop>30</pop> </forecastday> <forecastday> <period>5</period> <date> <epoch>1240876800</epoch> <pretty_short>6:00 PM MDT</pretty_short> <pretty>6:00 PM MDT on April 27, 2009</pretty> <day>27</day> <month>4</month> <year>2009</year> <yday>116</yday> <hour>18</hour> <min>00</min> <sec>0</sec> <isdst>1</isdst> <monthname>April</monthname> <weekday_short></weekday_short> <weekday>Monday</weekday> <ampm>PM</ampm> <tz_short>MDT</tz_short> <tz_long>America/Edmonton</tz_long> </date> <high> <fahrenheit>35</fahrenheit> <celsius>2</celsius> </high> <low> <fahrenheit>24</fahrenheit> <celsius>-4</celsius> </low> <conditions>Chance of Snow</conditions> <icon>chancesnow</icon> <skyicon>partlycloudy</skyicon> <pop>30</pop> </forecastday> <forecastday> <period>6</period> <date> <epoch>1240963200</epoch> <pretty_short>6:00 PM MDT</pretty_short> <pretty>6:00 PM MDT on April 28, 2009</pretty> <day>28</day> <month>4</month> <year>2009</year> <yday>117</yday> <hour>18</hour> <min>00</min> <sec>0</sec> <isdst>1</isdst> <monthname>April</monthname> <weekday_short></weekday_short> <weekday>Tuesday</weekday> <ampm>PM</ampm> <tz_short>MDT</tz_short> <tz_long>America/Edmonton</tz_long> </date> <high> <fahrenheit>37</fahrenheit> <celsius>3</celsius> </high> <low> <fahrenheit>22</fahrenheit> <celsius>-5</celsius> </low> <conditions>Chance of Snow</conditions> <icon>chancesnow</icon> <skyicon>partlycloudy</skyicon> <pop>30</pop> </forecastday> </simpleforecast> <moon_phase> <percentIlluminated>2</percentIlluminated> <ageOfMoon>28</ageOfMoon> <current_time> <hour>16</hour> <minute>54</minute> </current_time> <sunset> <hour>20</hour> <minute>45</minute> </sunset> <sunrise> <hour>6</hour> <minute>23</minute> </sunrise> </moon_phase> </forecast>
|
@@ -0,0 +1 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" ?> <kml xmlns="http://earth.google.com/kml/2.0"><Response> <name>40.756054,-73.986951</name> <Status> <code>200</code> <request>geocode</request> </Status> <Placemark id="p1"> <address>1475 Broadway, New York, NY 10036, USA</address> <AddressDetails Accuracy="8" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>US</CountryNameCode><CountryName>USA</CountryName><AdministrativeArea><AdministrativeAreaName>NY</AdministrativeAreaName><Locality><LocalityName>New York</LocalityName><Thoroughfare><ThoroughfareName>1475 Broadway</ThoroughfareName></Thoroughfare><PostalCode><PostalCodeNumber>10036</PostalCodeNumber></PostalCode></Locality></AdministrativeArea></Country></AddressDetails> <ExtendedData> <LatLonBox north="40.7593486" south="40.7530534" east="-73.9833654" west="-73.9896606" /> </ExtendedData> <Point><coordinates>-73.9865130,40.7562010,0</coordinates></Point> </Placemark> <Placemark id="p2"> <address>Theater District - Times Square, New York, NY, USA</address> <AddressDetails Accuracy="4" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>US</CountryNameCode><CountryName>USA</CountryName><AdministrativeArea><AdministrativeAreaName>NY</AdministrativeAreaName><Locality><LocalityName>New York</LocalityName><AddressLine>Theater District - Times Square</AddressLine></Locality></AdministrativeArea></Country></AddressDetails> <ExtendedData> <LatLonBox north="40.7641790" south="40.7537300" east="-73.9790780" west="-73.9908821" /> </ExtendedData> <Point><coordinates>-73.9844722,40.7590110,0</coordinates></Point> </Placemark> <Placemark id="p3"> <address>New York 10036, USA</address> <AddressDetails Accuracy="5" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>US</CountryNameCode><CountryName>USA</CountryName><AdministrativeArea><AdministrativeAreaName>NY</AdministrativeAreaName><PostalCode><PostalCodeNumber>10036</PostalCodeNumber></PostalCode></AdministrativeArea></Country></AddressDetails> <ExtendedData> <LatLonBox north="40.7654810" south="40.7534830" east="-73.9781150" west="-74.0016340" /> </ExtendedData> <Point><coordinates>-73.9903489,40.7598450,0</coordinates></Point> </Placemark> <Placemark id="p4"> <address>Midtown, New York, NY, USA</address> <AddressDetails Accuracy="4" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>US</CountryNameCode><CountryName>USA</CountryName><AdministrativeArea><AdministrativeAreaName>NY</AdministrativeAreaName><Locality><LocalityName>New York</LocalityName><AddressLine>Midtown</AddressLine></Locality></AdministrativeArea></Country></AddressDetails> <ExtendedData> <LatLonBox north="40.8060980" south="40.7273300" east="-73.9422169" west="-74.0088202" /> </ExtendedData> <Point><coordinates>-73.9771260,40.7690810,0</coordinates></Point> </Placemark> <Placemark id="p5"> <address>Manhattan, New York, USA</address> <AddressDetails Accuracy="4" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>US</CountryNameCode><CountryName>USA</CountryName><AdministrativeArea><AdministrativeAreaName>NY</AdministrativeAreaName><AddressLine>Manhattan</AddressLine></AdministrativeArea></Country></AddressDetails> <ExtendedData> <LatLonBox north="40.8820000" south="40.6795170" east="-73.9072000" west="-74.0472500" /> </ExtendedData> <Point><coordinates>-73.9712488,40.7830603,0</coordinates></Point> </Placemark> <Placemark id="p6"> <address>New York, New York, USA</address> <AddressDetails Accuracy="3" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>US</CountryNameCode><CountryName>USA</CountryName><AdministrativeArea><AdministrativeAreaName>NY</AdministrativeAreaName><AddressLine>New York</AddressLine></AdministrativeArea></Country></AddressDetails> <ExtendedData> <LatLonBox north="40.8820000" south="40.6795170" east="-73.9072000" west="-74.0472500" /> </ExtendedData> <Point><coordinates>-73.9712488,40.7830603,0</coordinates></Point> </Placemark> <Placemark id="p7"> <address>New York, NY, USA</address> <AddressDetails Accuracy="4" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>US</CountryNameCode><CountryName>USA</CountryName><AdministrativeArea><AdministrativeAreaName>NY</AdministrativeAreaName><Locality><LocalityName>New York</LocalityName></Locality></AdministrativeArea></Country></AddressDetails> <ExtendedData> <LatLonBox north="40.9174990" south="40.4773830" east="-73.6997930" west="-74.2590900" /> </ExtendedData> <Point><coordinates>-73.9869510,40.7560540,0</coordinates></Point> </Placemark> <Placemark id="p8"> <address>New York, USA</address> <AddressDetails Accuracy="2" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>US</CountryNameCode><CountryName>USA</CountryName><AdministrativeArea><AdministrativeAreaName>NY</AdministrativeAreaName></AdministrativeArea></Country></AddressDetails> <ExtendedData> <LatLonBox north="45.0158510" south="40.4773830" east="-71.7774920" west="-79.7625900" /> </ExtendedData> <Point><coordinates>-74.2179326,43.2994285,0</coordinates></Point> </Placemark> <Placemark id="p9"> <address>United States</address> <AddressDetails Accuracy="1" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>US</CountryNameCode><CountryName>USA</CountryName></Country></AddressDetails> <ExtendedData> <LatLonBox north="71.4343570" south="17.8315100" east="-65.1685040" west="172.3478480" /> </ExtendedData> <Point><coordinates>-95.7128910,37.0902400,0</coordinates></Point> </Placemark> </Response></kml>
|
@@ -0,0 +1 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" ?> <kml xmlns="http://earth.google.com/kml/2.0"><Response> <name>90210</name> <Status> <code>200</code> <request>geocode</request> </Status> <Placemark id="p1"> <address>Beverly Hills, CA 90210, USA</address> <AddressDetails Accuracy="5" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>US</CountryNameCode><CountryName>USA</CountryName><AdministrativeArea><AdministrativeAreaName>CA</AdministrativeAreaName><Locality><LocalityName>Beverly Hills</LocalityName><PostalCode><PostalCodeNumber>90210</PostalCodeNumber></PostalCode></Locality></AdministrativeArea></Country></AddressDetails> <ExtendedData> <LatLonBox north="34.1391900" south="34.0670180" east="-118.3897100" west="-118.4427960" /> </ExtendedData> <Point><coordinates>-118.4104684,34.1030032,0</coordinates></Point> </Placemark> </Response></kml>
|
@@ -0,0 +1 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" ?> <kml xmlns="http://earth.google.com/kml/2.0"><Response> <name>T5B 4M9</name> <Status> <code>200</code> <request>geocode</request> </Status> <Placemark id="p1"> <address>Alberta T5B 4M9, Canada</address> <AddressDetails Accuracy="5" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>CA</CountryNameCode><CountryName>Canada</CountryName><AdministrativeArea><AdministrativeAreaName>AB</AdministrativeAreaName><PostalCode><PostalCodeNumber>T5B 4M9</PostalCodeNumber></PostalCode></AdministrativeArea></Country></AddressDetails> <ExtendedData> <LatLonBox north="53.5735946" south="53.5672994" east="-113.4529354" west="-113.4592306" /> </ExtendedData> <Point><coordinates>-113.4560830,53.5704470,0</coordinates></Point> </Placemark> </Response></kml>
|
@@ -0,0 +1 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" ?> <kml xmlns="http://earth.google.com/kml/2.0"><Response> <name>Calgary,AB</name> <Status> <code>200</code> <request>geocode</request> </Status> <Placemark id="p1"> <address>Calgary, AB, Canada</address> <AddressDetails Accuracy="4" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>CA</CountryNameCode><CountryName>Canada</CountryName><AdministrativeArea><AdministrativeAreaName>AB</AdministrativeAreaName><Locality><LocalityName>Calgary</LocalityName></Locality></AdministrativeArea></Country></AddressDetails> <ExtendedData> <LatLonBox north="51.1838270" south="50.8417840" east="-113.9057040" west="-114.2713780" /> </ExtendedData> <Point><coordinates>-114.0624380,51.0551490,0</coordinates></Point> </Placemark> </Response></kml>
|
@@ -0,0 +1 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" ?> <kml xmlns="http://earth.google.com/kml/2.0"><Response> <name>New York, NY</name> <Status> <code>200</code> <request>geocode</request> </Status> <Placemark id="p1"> <address>New York, NY, USA</address> <AddressDetails Accuracy="4" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>US</CountryNameCode><CountryName>USA</CountryName><AdministrativeArea><AdministrativeAreaName>NY</AdministrativeAreaName><Locality><LocalityName>New York</LocalityName></Locality></AdministrativeArea></Country></AddressDetails> <ExtendedData> <LatLonBox north="40.9174990" south="40.4773830" east="-73.6997930" west="-74.2590900" /> </ExtendedData> <Point><coordinates>-73.9869510,40.7560540,0</coordinates></Point> </Placemark> </Response></kml>
|
@@ -0,0 +1 @@
|
|
1
|
+
<?xml version="1.0"?><xml_api_reply version="1"><weather module_id="0" tab_id="0" mobile_row="0" mobile_zipped="1" row="0" section="0" ><forecast_information><city data="Calgary, AB"/><postal_code data="Calgary,AB"/><latitude_e6 data=""/><longitude_e6 data=""/><forecast_date data="2009-04-26"/><current_date_time data="2009-04-26 15:14:15 +0000"/><unit_system data="US"/></forecast_information><current_conditions><condition data="Cloudy"/><temp_f data="32"/><temp_c data="0"/><humidity data="Humidity: 64%"/><icon data="/images/weather/cloudy.gif"/><wind_condition data="Wind: NW at 5 mph"/></current_conditions><forecast_conditions><day_of_week data="Sun"/><low data="24"/><high data="42"/><icon data="/images/weather/rain.gif"/><condition data="Sleet"/></forecast_conditions><forecast_conditions><day_of_week data="Mon"/><low data="22"/><high data="37"/><icon data="/images/weather/rain.gif"/><condition data="Sleet"/></forecast_conditions><forecast_conditions><day_of_week data="Tue"/><low data="24"/><high data="40"/><icon data="/images/weather/rain.gif"/><condition data="Sleet"/></forecast_conditions><forecast_conditions><day_of_week data="Wed"/><low data="21"/><high data="43"/><icon data="/images/weather/mostly_cloudy.gif"/><condition data="Mostly Cloudy"/></forecast_conditions></weather></xml_api_reply>
|
@@ -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 - Beverly Hills, CA</title> <link>http://us.rd.yahoo.com/dailynews/rss/weather/Beverly_Hills__CA/*http://weather.yahoo.com/forecast/90210_c.html</link> <description>Yahoo! Weather for Beverly Hills, CA</description> <language>en-us</language> <lastBuildDate>Sun, 26 Apr 2009 10:51 am PDT</lastBuildDate> <ttl>60</ttl> <yweather:location city="Beverly Hills" region="CA" country="US"/> <yweather:units temperature="C" distance="km" pressure="mb" speed="kph"/> <yweather:wind chill="17" direction="0" speed="4.83" /> <yweather:atmosphere humidity="50" visibility="16.09" pressure="1017" rising="0" /> <yweather:astronomy sunrise="6:09 am" sunset="7:34 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 Beverly Hills, CA at 10:51 am PDT</title> <geo:lat>34.08</geo:lat> <geo:long>-118.4</geo:long> <link>http://us.rd.yahoo.com/dailynews/rss/weather/Beverly_Hills__CA/*http://weather.yahoo.com/forecast/90210_c.html</link> <pubDate>Sun, 26 Apr 2009 10:51 am PDT</pubDate> <yweather:condition text="Partly Cloudy" code="30" temp="17" date="Sun, 26 Apr 2009 10:51 am PDT" /> <description><![CDATA[ <img src="http://l.yimg.com/a/i/us/we/52/30.gif"/><br /> <b>Current Conditions:</b><br /> Partly Cloudy, 17 C<BR /> <BR /><b>Forecast:</b><BR /> Sun - Mostly Sunny. High: 19 Low: 11<br /> Mon - Cloudy. High: 18 Low: 11<br /> <br /> <a href="http://us.rd.yahoo.com/dailynews/rss/weather/Beverly_Hills__CA/*http://weather.yahoo.com/forecast/USCA0090_c.html">Full Forecast at Yahoo! Weather</a><BR/> (provided by The Weather Channel)<br/> ]]></description> <yweather:forecast day="Sun" date="26 Apr 2009" low="11" high="19" text="Mostly Sunny" code="34" /> <yweather:forecast day="Mon" date="27 Apr 2009" low="11" high="18" text="Cloudy" code="26" /> <guid isPermaLink="false">90210_2009_04_26_10_51_PDT</guid> </item> </channel> </rss><!-- api2.weather.sp1.yahoo.com compressed/chunked Sun Apr 26 11:25:45 PDT 2009 -->
|
data/spec/query_spec.rb
ADDED
@@ -0,0 +1,469 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Query" do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@zipcode = "90210"
|
7
|
+
@postal_code = "T5B 4M9"
|
8
|
+
@coordinates = "40.756054,-73.986951"
|
9
|
+
@geocode = "New York, NY"
|
10
|
+
|
11
|
+
# actual conversions
|
12
|
+
@zipcode_to_coordinates = "34.1030032,-118.4104684"
|
13
|
+
@zipcode_to_geocode = "Beverly Hills, CA, USA"
|
14
|
+
@postalcode_to_coordinates = "53.570447,-113.456083"
|
15
|
+
@geocode_to_coordinates = "40.756054,-73.986951"
|
16
|
+
@coordinates_to_geocode = "New York, NY, USA"
|
17
|
+
|
18
|
+
Barometer.google_geocode_key = nil
|
19
|
+
Barometer::Query.google_geocode_key = nil
|
20
|
+
#Barometer.skip_graticule = true
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "the class methods" do
|
24
|
+
|
25
|
+
it "detects a zipcode" do
|
26
|
+
Barometer::Query.is_us_zipcode?(@zipcode).should be_true
|
27
|
+
Barometer::Query.is_us_zipcode?(@postal_code).should be_false
|
28
|
+
Barometer::Query.is_us_zipcode?(@coordinates).should be_false
|
29
|
+
end
|
30
|
+
|
31
|
+
it "detects a postalcode" do
|
32
|
+
Barometer::Query.is_canadian_postcode?(@postal_code).should be_true
|
33
|
+
Barometer::Query.is_canadian_postcode?(@zipcode).should be_false
|
34
|
+
Barometer::Query.is_canadian_postcode?(@coordinates).should be_false
|
35
|
+
end
|
36
|
+
|
37
|
+
it "detects a coordinates" do
|
38
|
+
Barometer::Query.is_coordinates?(@coordinates).should be_true
|
39
|
+
Barometer::Query.is_coordinates?(@zipcode).should be_false
|
40
|
+
Barometer::Query.is_coordinates?(@postal_code).should be_false
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "determines the query format" do
|
46
|
+
|
47
|
+
before(:each) do
|
48
|
+
@query = Barometer::Query.new
|
49
|
+
@query.country_code.should be_nil
|
50
|
+
end
|
51
|
+
|
52
|
+
it "recognizes a zip code" do
|
53
|
+
@query.q = @zipcode
|
54
|
+
@query.format.should be_nil
|
55
|
+
@query.analyze!
|
56
|
+
@query.format.to_sym.should == :zipcode
|
57
|
+
|
58
|
+
@query.country_code.should == "US"
|
59
|
+
@query.zipcode?.should be_true
|
60
|
+
@query.postalcode?.should be_false
|
61
|
+
@query.coordinates?.should be_false
|
62
|
+
@query.geocode?.should be_false
|
63
|
+
end
|
64
|
+
|
65
|
+
it "recognizes a postal code" do
|
66
|
+
@query.q = @postal_code
|
67
|
+
@query.format.should be_nil
|
68
|
+
@query.analyze!
|
69
|
+
@query.format.to_sym.should == :postalcode
|
70
|
+
|
71
|
+
@query.country_code.should == "CA"
|
72
|
+
@query.zipcode?.should be_false
|
73
|
+
@query.postalcode?.should be_true
|
74
|
+
@query.coordinates?.should be_false
|
75
|
+
@query.geocode?.should be_false
|
76
|
+
end
|
77
|
+
|
78
|
+
it "recognizes latitude/longitude" do
|
79
|
+
@query.q = @coordinates
|
80
|
+
@query.format.should be_nil
|
81
|
+
@query.analyze!
|
82
|
+
@query.format.to_sym.should == :coordinates
|
83
|
+
|
84
|
+
@query.country_code.should be_nil
|
85
|
+
@query.zipcode?.should be_false
|
86
|
+
@query.postalcode?.should be_false
|
87
|
+
@query.coordinates?.should be_true
|
88
|
+
@query.geocode?.should be_false
|
89
|
+
end
|
90
|
+
|
91
|
+
it "defaults to a general geo_location" do
|
92
|
+
@query.q = @geocode
|
93
|
+
@query.format.should be_nil
|
94
|
+
@query.analyze!
|
95
|
+
@query.format.to_sym.should == :geocode
|
96
|
+
|
97
|
+
@query.country_code.should be_nil
|
98
|
+
@query.zipcode?.should be_false
|
99
|
+
@query.postalcode?.should be_false
|
100
|
+
@query.coordinates?.should be_false
|
101
|
+
@query.geocode?.should be_true
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
describe "when initialized" do
|
107
|
+
|
108
|
+
before(:each) do
|
109
|
+
@query = Barometer::Query.new
|
110
|
+
end
|
111
|
+
|
112
|
+
it "responds to q" do
|
113
|
+
@query.q.should be_nil
|
114
|
+
end
|
115
|
+
|
116
|
+
# it "responds to geo" do
|
117
|
+
# @query.geo.should be_nil
|
118
|
+
# end
|
119
|
+
|
120
|
+
it "responds to format" do
|
121
|
+
@query.format.should be_nil
|
122
|
+
end
|
123
|
+
|
124
|
+
it "responds to country_code" do
|
125
|
+
@query.country_code.should be_nil
|
126
|
+
end
|
127
|
+
|
128
|
+
it "sets the query" do
|
129
|
+
query = Barometer::Query.new(@geocode)
|
130
|
+
query.q.should == @geocode
|
131
|
+
end
|
132
|
+
|
133
|
+
it "determines the format" do
|
134
|
+
query = Barometer::Query.new(@geocode)
|
135
|
+
query.format.should_not be_nil
|
136
|
+
end
|
137
|
+
|
138
|
+
it "responds to google_api_key" do
|
139
|
+
Barometer::Query.google_geocode_key.should be_nil
|
140
|
+
end
|
141
|
+
|
142
|
+
it "sets the google_api_key" do
|
143
|
+
key = "KEY"
|
144
|
+
Barometer::Query.google_geocode_key = key
|
145
|
+
Barometer::Query.google_geocode_key.should == key
|
146
|
+
end
|
147
|
+
|
148
|
+
it "defaults to the Module geocode key" do
|
149
|
+
key = "KEY"
|
150
|
+
Barometer::Query.google_geocode_key.should be_nil
|
151
|
+
Barometer.google_geocode_key = key
|
152
|
+
Barometer::Query.google_geocode_key.should == key
|
153
|
+
end
|
154
|
+
|
155
|
+
it "responds to preferred" do
|
156
|
+
@query.preferred.should be_nil
|
157
|
+
end
|
158
|
+
|
159
|
+
it "responds to geo" do
|
160
|
+
@query.geo.should be_nil
|
161
|
+
end
|
162
|
+
|
163
|
+
end
|
164
|
+
|
165
|
+
use_graticule = true
|
166
|
+
|
167
|
+
if use_graticule
|
168
|
+
describe "when converting queries" do
|
169
|
+
|
170
|
+
before(:each) do
|
171
|
+
@key = "ABQIAAAAq8TH4offRcGrok8JVY_MyxRi_j0U6kJrkFvY4-OX2XYmEAa76BSFwMlSow1YgX8BOPUeve_shMG7xw"
|
172
|
+
url_start = "http://maps.google.com/maps/geo?"
|
173
|
+
#
|
174
|
+
# for Graticule and/or HTTParty geocoding
|
175
|
+
#
|
176
|
+
FakeWeb.register_uri(:get,
|
177
|
+
"#{url_start}gl=US&key=#{@key}&output=xml&q=90210",
|
178
|
+
:string => File.read(File.join(File.dirname(__FILE__),
|
179
|
+
'fixtures',
|
180
|
+
'geocode_90210.xml')
|
181
|
+
)
|
182
|
+
)
|
183
|
+
FakeWeb.register_uri(:get,
|
184
|
+
"#{url_start}gl=CA&key=#{@key}&output=xml&q=T5B%204M9",
|
185
|
+
:string => File.read(File.join(File.dirname(__FILE__),
|
186
|
+
'fixtures',
|
187
|
+
'geocode_T5B4M9.xml')
|
188
|
+
)
|
189
|
+
)
|
190
|
+
#
|
191
|
+
# for Graticule geocoding
|
192
|
+
#
|
193
|
+
FakeWeb.register_uri(:get,
|
194
|
+
"#{url_start}gl=&key=#{@key}&output=xml&q=New%20York,%20NY",
|
195
|
+
:string => File.read(File.join(File.dirname(__FILE__),
|
196
|
+
'fixtures',
|
197
|
+
'geocode_newyork_ny.xml')
|
198
|
+
)
|
199
|
+
)
|
200
|
+
FakeWeb.register_uri(:get,
|
201
|
+
"#{url_start}gl=&key=#{@key}&output=xml&q=40.756054,-73.986951",
|
202
|
+
:string => File.read(File.join(File.dirname(__FILE__),
|
203
|
+
'fixtures',
|
204
|
+
'geocode_40_73.xml')
|
205
|
+
)
|
206
|
+
)
|
207
|
+
#
|
208
|
+
# for HTTParty geocoding
|
209
|
+
#
|
210
|
+
FakeWeb.register_uri(:get,
|
211
|
+
"#{url_start}output=xml&q=New%20York%2C%20NY&gl=&key=#{@key}",
|
212
|
+
:string => File.read(File.join(File.dirname(__FILE__),
|
213
|
+
'fixtures',
|
214
|
+
'geocode_newyork_ny.xml')
|
215
|
+
)
|
216
|
+
)
|
217
|
+
FakeWeb.register_uri(:get,
|
218
|
+
"#{url_start}gl=&output=xml&q=#{CGI.escape("40.756054,-73.986951")}&key=#{@key}",
|
219
|
+
:string => File.read(File.join(File.dirname(__FILE__),
|
220
|
+
'fixtures',
|
221
|
+
'geocode_40_73.xml')
|
222
|
+
)
|
223
|
+
)
|
224
|
+
end
|
225
|
+
|
226
|
+
describe "to coordinates," do
|
227
|
+
|
228
|
+
before(:each) do
|
229
|
+
Barometer::Query.google_geocode_key = @key
|
230
|
+
end
|
231
|
+
|
232
|
+
it "skips conversion unless Graticule enabled or no API key" do
|
233
|
+
Barometer::Query.google_geocode_key = nil
|
234
|
+
Barometer::Query.google_geocode_key.should be_nil
|
235
|
+
Barometer.google_geocode_key = nil
|
236
|
+
Barometer.google_geocode_key.should be_nil
|
237
|
+
Barometer::Query.to_coordinates(@geocode, :geocode).should be_nil
|
238
|
+
end
|
239
|
+
|
240
|
+
it "attempts conversion if Graticule enabled and has API key" do
|
241
|
+
Barometer::Query.to_coordinates(@geocode, :geocode).should_not be_nil
|
242
|
+
end
|
243
|
+
|
244
|
+
it "converts from geocode" do
|
245
|
+
Barometer::Query.to_coordinates(@geocode, :geocode).first.should == "40.756054,-73.986951"
|
246
|
+
end
|
247
|
+
|
248
|
+
it "converts from zipcode" do
|
249
|
+
Barometer::Query.to_coordinates(@zipcode, :zipcode).first.should == "34.1030032,-118.4104684"
|
250
|
+
end
|
251
|
+
|
252
|
+
it "converts from postalcode" do
|
253
|
+
Barometer::Query.to_coordinates(@postal_code, :postalcode).first.should == "53.570447,-113.456083"
|
254
|
+
end
|
255
|
+
|
256
|
+
end
|
257
|
+
|
258
|
+
describe "to geocode" do
|
259
|
+
|
260
|
+
before(:each) do
|
261
|
+
Barometer::Query.google_geocode_key = @key
|
262
|
+
end
|
263
|
+
|
264
|
+
describe "when Graticule enabled," do
|
265
|
+
|
266
|
+
it "converts from coordinates" do
|
267
|
+
Barometer::Query.to_geocode(@coordinates, :coordinates).first.should == "New York, NY, USA"
|
268
|
+
end
|
269
|
+
|
270
|
+
it "converts from zipcode" do
|
271
|
+
Barometer::Query.to_geocode(@zipcode, :zipcode).first.should == "Beverly Hills, CA, USA"
|
272
|
+
end
|
273
|
+
|
274
|
+
it "converts from postalcode" do
|
275
|
+
Barometer::Query.to_geocode(@postal_code, :postalcode).first.should == @postal_code
|
276
|
+
end
|
277
|
+
|
278
|
+
end
|
279
|
+
|
280
|
+
describe "when Graticule disabled," do
|
281
|
+
|
282
|
+
it "uses coordinates" do
|
283
|
+
Barometer::Query.google_geocode_key = nil
|
284
|
+
Barometer::Query.google_geocode_key.should be_nil
|
285
|
+
Barometer.google_geocode_key = nil
|
286
|
+
Barometer.google_geocode_key.should be_nil
|
287
|
+
Barometer::Query.to_geocode(@coordinates, :coordinates).first.should == @coordinates
|
288
|
+
end
|
289
|
+
|
290
|
+
it "uses zipcode" do
|
291
|
+
Barometer::Query.google_geocode_key = nil
|
292
|
+
Barometer::Query.google_geocode_key.should be_nil
|
293
|
+
Barometer.google_geocode_key = nil
|
294
|
+
Barometer.google_geocode_key.should be_nil
|
295
|
+
Barometer::Query.to_geocode(@zipcode, :zipcode).first.should == @zipcode
|
296
|
+
end
|
297
|
+
|
298
|
+
it "uses postalcode" do
|
299
|
+
Barometer::Query.google_geocode_key = nil
|
300
|
+
Barometer::Query.google_geocode_key.should be_nil
|
301
|
+
Barometer.google_geocode_key = nil
|
302
|
+
Barometer.google_geocode_key.should be_nil
|
303
|
+
Barometer::Query.to_geocode(@postal_code, :postalcode).first.should == @postal_code
|
304
|
+
end
|
305
|
+
|
306
|
+
end
|
307
|
+
|
308
|
+
end
|
309
|
+
|
310
|
+
end
|
311
|
+
|
312
|
+
describe "when returning the query to a Weather API" do
|
313
|
+
|
314
|
+
it "raises an error if there are NO acceptable formats" do
|
315
|
+
acceptable_formats = nil
|
316
|
+
query = Barometer::Query.new
|
317
|
+
lambda { query.convert!(acceptable_formats) }.should raise_error
|
318
|
+
|
319
|
+
acceptable_formats = []
|
320
|
+
lambda { query.convert!(acceptable_formats) }.should raise_error
|
321
|
+
end
|
322
|
+
|
323
|
+
describe "and the query is already of an acceptable format" do
|
324
|
+
|
325
|
+
before(:each) do
|
326
|
+
# all formats accepted
|
327
|
+
@acceptable_formats = [:zipcode, :postalcode, :geocode, :coordinates]
|
328
|
+
end
|
329
|
+
|
330
|
+
it "returns the zipcode untouched" do
|
331
|
+
query = Barometer::Query.new(@zipcode)
|
332
|
+
query.convert!(@acceptable_formats).should == @zipcode
|
333
|
+
query.country_code.should == "US"
|
334
|
+
end
|
335
|
+
|
336
|
+
it "returns the postalcode untouched" do
|
337
|
+
query = Barometer::Query.new(@postal_code)
|
338
|
+
query.convert!(@acceptable_formats).should == @postal_code
|
339
|
+
query.country_code.should == "CA"
|
340
|
+
end
|
341
|
+
|
342
|
+
it "returns the coordinates untouched" do
|
343
|
+
query = Barometer::Query.new(@coordinates)
|
344
|
+
query.convert!(@acceptable_formats).should == @coordinates
|
345
|
+
end
|
346
|
+
|
347
|
+
it "returns the geocode untouched" do
|
348
|
+
query = Barometer::Query.new(@geocode)
|
349
|
+
query.convert!(@acceptable_formats).should == @geocode
|
350
|
+
end
|
351
|
+
|
352
|
+
end
|
353
|
+
|
354
|
+
describe "and the query needs converting" do
|
355
|
+
|
356
|
+
describe "with an intial format of :zipcode," do
|
357
|
+
|
358
|
+
before(:each) do
|
359
|
+
@query = Barometer::Query.new(@zipcode)
|
360
|
+
Barometer::Query.google_geocode_key = "ABQIAAAAq8TH4offRcGrok8JVY_MyxRi_j0U6kJrkFvY4-OX2XYmEAa76BSFwMlSow1YgX8BOPUeve_shMG7xw"
|
361
|
+
end
|
362
|
+
|
363
|
+
it "converts to coordinates" do
|
364
|
+
acceptable_formats = [:coordinates]
|
365
|
+
@query.convert!(acceptable_formats).should == @zipcode_to_coordinates
|
366
|
+
@query.country_code.should == "US"
|
367
|
+
end
|
368
|
+
|
369
|
+
it "converts to geocode" do
|
370
|
+
acceptable_formats = [:geocode]
|
371
|
+
@query.convert!(acceptable_formats).should == @zipcode_to_geocode
|
372
|
+
@query.country_code.should == "US"
|
373
|
+
end
|
374
|
+
|
375
|
+
it "skips converting to postalcode" do
|
376
|
+
acceptable_formats = [:postalcode]
|
377
|
+
@query.convert!(acceptable_formats).should be_nil
|
378
|
+
@query.country_code.should == "US"
|
379
|
+
end
|
380
|
+
|
381
|
+
end
|
382
|
+
|
383
|
+
describe "with an intial format of :postalcode," do
|
384
|
+
|
385
|
+
before(:each) do
|
386
|
+
@query = Barometer::Query.new(@postal_code)
|
387
|
+
Barometer::Query.google_geocode_key = "ABQIAAAAq8TH4offRcGrok8JVY_MyxRi_j0U6kJrkFvY4-OX2XYmEAa76BSFwMlSow1YgX8BOPUeve_shMG7xw"
|
388
|
+
end
|
389
|
+
|
390
|
+
it "converts to coordinates" do
|
391
|
+
acceptable_formats = [:coordinates]
|
392
|
+
@query.convert!(acceptable_formats).should == @postalcode_to_coordinates
|
393
|
+
@query.country_code.should == "CA"
|
394
|
+
end
|
395
|
+
|
396
|
+
it "skips converting to geocode" do
|
397
|
+
acceptable_formats = [:geocode]
|
398
|
+
@query.convert!(acceptable_formats).should == @postal_code
|
399
|
+
@query.country_code.should == "CA"
|
400
|
+
end
|
401
|
+
|
402
|
+
it "skips converting to zipcode" do
|
403
|
+
acceptable_formats = [:zipcode]
|
404
|
+
@query.convert!(acceptable_formats).should be_nil
|
405
|
+
@query.country_code.should == "CA"
|
406
|
+
end
|
407
|
+
|
408
|
+
end
|
409
|
+
|
410
|
+
describe "with an intial format of :geocode," do
|
411
|
+
|
412
|
+
before(:each) do
|
413
|
+
@query = Barometer::Query.new(@geocode)
|
414
|
+
Barometer::Query.google_geocode_key = "ABQIAAAAq8TH4offRcGrok8JVY_MyxRi_j0U6kJrkFvY4-OX2XYmEAa76BSFwMlSow1YgX8BOPUeve_shMG7xw"
|
415
|
+
end
|
416
|
+
|
417
|
+
it "converts to coordinates" do
|
418
|
+
acceptable_formats = [:coordinates]
|
419
|
+
@query.convert!(acceptable_formats).should == @geocode_to_coordinates
|
420
|
+
@query.country_code.should == "US"
|
421
|
+
end
|
422
|
+
|
423
|
+
it "skips converting to zipcode" do
|
424
|
+
acceptable_formats = [:zipcode]
|
425
|
+
@query.convert!(acceptable_formats).should be_nil
|
426
|
+
@query.country_code.should be_nil
|
427
|
+
end
|
428
|
+
|
429
|
+
it "skips converting to postalcode" do
|
430
|
+
acceptable_formats = [:postalcode]
|
431
|
+
@query.convert!(acceptable_formats).should be_nil
|
432
|
+
@query.country_code.should be_nil
|
433
|
+
end
|
434
|
+
|
435
|
+
end
|
436
|
+
|
437
|
+
describe "with an intial format of :coordinates," do
|
438
|
+
|
439
|
+
before(:each) do
|
440
|
+
@query = Barometer::Query.new(@coordinates)
|
441
|
+
Barometer::Query.google_geocode_key = "ABQIAAAAq8TH4offRcGrok8JVY_MyxRi_j0U6kJrkFvY4-OX2XYmEAa76BSFwMlSow1YgX8BOPUeve_shMG7xw"
|
442
|
+
end
|
443
|
+
|
444
|
+
it "converts to geocode" do
|
445
|
+
acceptable_formats = [:geocode]
|
446
|
+
@query.convert!(acceptable_formats).should == @coordinates_to_geocode
|
447
|
+
@query.country_code.should == "US"
|
448
|
+
end
|
449
|
+
|
450
|
+
it "skips converting to zipcode" do
|
451
|
+
acceptable_formats = [:zipcode]
|
452
|
+
@query.convert!(acceptable_formats).should be_nil
|
453
|
+
@query.country_code.should be_nil
|
454
|
+
end
|
455
|
+
|
456
|
+
it "skips converting to postalcode" do
|
457
|
+
acceptable_formats = [:postalcode]
|
458
|
+
@query.convert!(acceptable_formats).should be_nil
|
459
|
+
@query.country_code.should be_nil
|
460
|
+
end
|
461
|
+
|
462
|
+
end
|
463
|
+
|
464
|
+
end
|
465
|
+
|
466
|
+
end
|
467
|
+
end
|
468
|
+
|
469
|
+
end
|