barometer 0.5.0 → 0.6.1

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 (70) hide show
  1. data/README.rdoc +51 -9
  2. data/VERSION.yml +2 -2
  3. data/bin/barometer +57 -7
  4. data/lib/barometer.rb +11 -0
  5. data/lib/barometer/base.rb +3 -0
  6. data/lib/barometer/data.rb +11 -6
  7. data/lib/barometer/data/sun.rb +10 -0
  8. data/lib/barometer/data/zone.rb +79 -188
  9. data/lib/barometer/formats/coordinates.rb +4 -1
  10. data/lib/barometer/formats/geocode.rb +9 -7
  11. data/lib/barometer/formats/icao.rb +2 -2
  12. data/lib/barometer/formats/weather_id.rb +2 -2
  13. data/lib/barometer/measurements/common.rb +113 -0
  14. data/lib/barometer/{data → measurements}/current.rb +17 -42
  15. data/lib/barometer/measurements/forecast.rb +62 -0
  16. data/lib/barometer/measurements/forecast_array.rb +72 -0
  17. data/lib/barometer/{data → measurements}/measurement.rb +57 -45
  18. data/lib/barometer/measurements/night.rb +27 -0
  19. data/lib/barometer/query.rb +55 -5
  20. data/lib/barometer/services.rb +3 -1
  21. data/lib/barometer/translations/icao_country_codes.yml +274 -1
  22. data/lib/barometer/translations/weather_country_codes.yml +189 -6
  23. data/lib/barometer/translations/zone_codes.yml +360 -0
  24. data/lib/barometer/weather.rb +5 -4
  25. data/lib/barometer/weather_services/google.rb +19 -35
  26. data/lib/barometer/weather_services/service.rb +113 -255
  27. data/lib/barometer/weather_services/weather_bug.rb +291 -2
  28. data/lib/barometer/weather_services/weather_dot_com.rb +45 -54
  29. data/lib/barometer/weather_services/wunderground.rb +83 -89
  30. data/lib/barometer/weather_services/yahoo.rb +44 -91
  31. data/lib/barometer/web_services/geocode.rb +1 -0
  32. data/lib/barometer/web_services/timezone.rb +40 -0
  33. data/lib/barometer/web_services/weather_id.rb +17 -2
  34. data/lib/demometer/demometer.rb +28 -0
  35. data/lib/demometer/public/css/master.css +259 -1
  36. data/lib/demometer/public/css/print.css +94 -0
  37. data/lib/demometer/public/css/syntax.css +64 -0
  38. data/lib/demometer/public/images/link-out.gif +0 -0
  39. data/lib/demometer/views/about.erb +10 -0
  40. data/lib/demometer/views/index.erb +2 -0
  41. data/lib/demometer/views/layout.erb +3 -2
  42. data/lib/demometer/views/measurement.erb +4 -1
  43. data/lib/demometer/views/readme.erb +116 -88
  44. data/spec/data/sun_spec.rb +53 -0
  45. data/spec/data/zone_spec.rb +330 -100
  46. data/spec/fixtures/formats/weather_id/ksfo.xml +1 -0
  47. data/spec/fixtures/services/weather_bug/90210_current.xml +1 -0
  48. data/spec/fixtures/services/weather_bug/90210_forecast.xml +1 -0
  49. data/spec/formats/weather_id_spec.rb +10 -5
  50. data/spec/measurements/common_spec.rb +352 -0
  51. data/spec/{data → measurements}/current_spec.rb +40 -103
  52. data/spec/measurements/forecast_array_spec.rb +165 -0
  53. data/spec/measurements/forecast_spec.rb +135 -0
  54. data/spec/{data → measurements}/measurement_spec.rb +86 -107
  55. data/spec/measurements/night_measurement_spec.rb +49 -0
  56. data/spec/query_spec.rb +12 -2
  57. data/spec/spec_helper.rb +28 -1
  58. data/spec/weather_services/google_spec.rb +27 -117
  59. data/spec/weather_services/services_spec.rb +49 -1024
  60. data/spec/weather_services/weather_bug_spec.rb +274 -0
  61. data/spec/weather_services/weather_dot_com_spec.rb +45 -125
  62. data/spec/weather_services/wunderground_spec.rb +42 -136
  63. data/spec/weather_services/yahoo_spec.rb +26 -116
  64. data/spec/weather_spec.rb +45 -45
  65. metadata +27 -11
  66. data/lib/barometer/data/forecast.rb +0 -84
  67. data/lib/barometer/data/night.rb +0 -69
  68. data/lib/barometer/extensions/graticule.rb +0 -51
  69. data/spec/data/forecast_spec.rb +0 -192
  70. data/spec/data/night_measurement_spec.rb +0 -136
@@ -0,0 +1,27 @@
1
+ require 'date'
2
+ module Barometer
3
+ #
4
+ # Night Measurement
5
+ # a data class for forecasted night weather conditions
6
+ #
7
+ # This is basically a data holding class for the forecasted night
8
+ # weather conditions.
9
+ #
10
+ class Measurement::ForecastNight < Measurement::Common
11
+
12
+ attr_reader :date, :pop
13
+
14
+ # accessors (with input checking)
15
+ #
16
+ def date=(date)
17
+ raise ArgumentError unless date.is_a?(Date)
18
+ @date = date
19
+ end
20
+
21
+ def pop=(pop)
22
+ raise ArgumentError unless pop.is_a?(Fixnum)
23
+ @pop = pop
24
+ end
25
+
26
+ end
27
+ end
@@ -30,12 +30,14 @@ module Barometer
30
30
  :geocode => "Geocode"
31
31
  }
32
32
 
33
- attr_accessor :format, :q, :country_code, :geo
33
+ attr_accessor :format, :q, :country_code
34
+ attr_accessor :geo, :timezone, :conversions
34
35
 
35
36
  def initialize(query=nil)
36
37
  return unless query
37
38
  @q = query
38
39
  self.analyze!
40
+ @conversions = {}
39
41
  end
40
42
 
41
43
  # analyze the saved query to determine the format.
@@ -61,10 +63,16 @@ module Barometer
61
63
  raise ArgumentError unless (preferred_formats && preferred_formats.size > 0)
62
64
 
63
65
  # why convert if we are already there?
66
+ # (except in the case that the serivce excepts coordinates and we have a
67
+ # a geocode ... the google geocode results are superior)
68
+ #
64
69
  skip_conversion = false
65
- if preferred_formats.include?(@format.to_sym)
66
- skip_conversion = true
67
- converted_query = self.dup
70
+ unless (@format.to_sym == Query::Format::Geocode.format) &&
71
+ preferred_formats.include?(Query::Format::Coordinates.format)
72
+ if preferred_formats.include?(@format.to_sym)
73
+ skip_conversion = true
74
+ converted_query = self.dup
75
+ end
68
76
  end
69
77
 
70
78
  unless skip_conversion
@@ -78,11 +86,14 @@ module Barometer
78
86
  converted_query = Barometer::Query.new(@q)
79
87
  end
80
88
  unless converted
81
- converted_query = Query::Format.const_get(klass.to_s).to(self)
89
+ unless converted_query = get_conversion(preferred_format)
90
+ converted_query = Query::Format.const_get(klass.to_s).to(self)
91
+ end
82
92
  converted = true if converted_query
83
93
  end
84
94
  if converted
85
95
  converted_query.country_code ||= Query::Format.const_get(klass.to_s).country_code(converted_query.q)
96
+ post_conversion(converted_query)
86
97
  break
87
98
  end
88
99
  end
@@ -94,13 +105,52 @@ module Barometer
94
105
  if converted_query && converted_query.geo
95
106
  @geo = converted_query.geo
96
107
  else
108
+ puts "enhance geocode: #{converted_query.q}" if Barometer::debug?
97
109
  geo_query = Query::Format::Coordinates.to(converted_query)
98
110
  @geo = geo_query.geo if (geo_query && geo_query.geo)
111
+ converted_query.geo = @geo.dup
112
+ end
113
+ end
114
+
115
+ # enhance timezone?, unless we already did
116
+ #
117
+ if Barometer.enhance_timezone && !@timezone
118
+ if converted_query && converted_query.timezone
119
+ @geo = converted_query.timezone
120
+ elsif @geo && @geo.latitude && @geo.longitude
121
+ puts "enhance timezone: #{@geo.latitude}, #{@geo.longitude}" if Barometer::debug?
122
+ @timezone = WebService::Timezone.fetch(@geo.latitude,@geo.longitude)
123
+ converted_query.timezone = @timezone.dup
99
124
  end
100
125
  end
101
126
 
102
127
  converted_query
103
128
  end
104
129
 
130
+ # save the important parts of the conversion ... by saving conversion we
131
+ # can avoid doing the same conversion multiple times
132
+ #
133
+ def post_conversion(converted_query)
134
+ return unless (converted_query && converted_query.q && converted_query.format)
135
+ @conversions = {} unless @conversions
136
+ return if @conversions.has_key?(converted_query.format.to_sym)
137
+ puts "store: #{self.format} -> #{converted_query.format.to_sym} = #{self.q} -> #{converted_query.q}" if Barometer::debug?
138
+ @conversions[converted_query.format.to_sym] = converted_query.q
139
+ end
140
+
141
+ def get_conversion(format)
142
+ return nil unless format && @conversions
143
+ puts "found: #{self.format} -> #{format.to_sym} = #{self.q} -> #{@conversions[format.to_sym]}" if Barometer::debug? && @conversions.has_key?(format.to_sym)
144
+ # re-constuct converted query
145
+ if q = @conversions[format.to_sym]
146
+ converted_query = self.dup
147
+ converted_query.q = q
148
+ converted_query.format = format
149
+ converted_query
150
+ else
151
+ nil
152
+ end
153
+ end
154
+
105
155
  end
106
156
  end
@@ -7,10 +7,12 @@ require 'weather_services/wunderground'
7
7
  require 'weather_services/google'
8
8
  require 'weather_services/yahoo'
9
9
  require 'weather_services/weather_dot_com'
10
+ require 'weather_services/weather_bug'
10
11
 
11
12
  #
12
13
  # web services (non weather)
13
14
  #
14
15
  require 'web_services/web_service'
15
16
  require 'web_services/geocode'
16
- require 'web_services/weather_id'
17
+ require 'web_services/weather_id'
18
+ require 'web_services/timezone'
@@ -1,9 +1,282 @@
1
1
  # first term - icao code
2
2
  # second term - standard country_code
3
3
  #
4
+ # http://en.wikipedia.org/wiki/International_Civil_Aviation_Organization_airport_code
5
+ # http://www.theodora.com/country_digraphs.html
6
+ # http://www.unc.edu/~rowlett/units/codes/country.htm
7
+ #
4
8
  one_letter:
5
9
  C : CA
6
10
  K : US
11
+ U : RU
12
+ Y : AU
13
+ Z : CN
7
14
 
8
15
  two_letter:
9
- ET : DE
16
+ # A - Western South Pacific
17
+ AG : SB
18
+ AN : NR
19
+ AY : PG
20
+
21
+ # B - Iceland/Greenland and Kosovo
22
+ BG : GL
23
+ BI : IS
24
+ #BK : Kosovo (also LY Serbia (RS) because of disputes)
25
+
26
+ # D - West Africa
27
+ DA : DZ
28
+ DB : BJ
29
+ DF : BF
30
+ DG : GH
31
+ DI : CI
32
+ DN : NG
33
+ DR : NE
34
+ DT : TN
35
+ # DX : Togolese Republic
36
+
37
+ # E - Northern Europe
38
+ EB : BE
39
+ ED : DE
40
+ EE : EE
41
+ EF : FI
42
+ EG : GB
43
+ EH : NL
44
+ EI : IE
45
+ EK : DK
46
+ EL : LU
47
+ EN : NO
48
+ EP : PL
49
+ ES : SE
50
+ ET : DE
51
+ EV : LV
52
+ EY : LT
53
+
54
+ # F - Southern Africa
55
+ FA : ZA
56
+ FB : BW
57
+ FC : CG
58
+ FD : SZ
59
+ FE : CF
60
+ FG : GQ
61
+ # FH : Ascension Island (none)
62
+ FI : MU
63
+ FJ : IO
64
+ FK : CM
65
+ FL : ZM
66
+ # FM : Comoros (none), Madagascar (MG), Mayotte (YT), Réunion (RE)
67
+ FN : AO
68
+ FO : GA
69
+ FP : ST
70
+ FQ : MZ
71
+ FS : SC
72
+ FT : TD
73
+ FV : ZW
74
+ FW : MW
75
+ FX : LS
76
+ FY : NA
77
+ FZ : CD
78
+
79
+ # G - Northwestern Africa
80
+ GA : ML
81
+ GB : GM
82
+ GC : ES
83
+ GE : ES
84
+ GF : SL
85
+ GG : GW
86
+ GL : LR
87
+ GM : MA
88
+ GO : SN
89
+ GQ : MR
90
+ GS : EH
91
+ GU : GN
92
+ GV : CV
93
+
94
+ # H - Northeastern Africa
95
+ HA : ET
96
+ HB : BI
97
+ HC : SO
98
+ HD : DJ
99
+ HE : EG
100
+ HF : DJ
101
+ HH : ER
102
+ HK : KE
103
+ HL : LY
104
+ HR : RW
105
+ HS : SD
106
+ HT : TZ
107
+ HU : UG
108
+
109
+ # L - Southern Europe,Israel and Turkey
110
+ LA : AL
111
+ LB : BG
112
+ LC : CY
113
+ LD : HR
114
+ LE : ES
115
+ LF : FR
116
+ LG : GR
117
+ LH : HU
118
+ LI : IT
119
+ LJ : SI
120
+ LK : CZ
121
+ LL : IL
122
+ LM : MT
123
+ LN : MC
124
+ LO : AT
125
+ LP : PT
126
+ LQ : BA
127
+ LR : RO
128
+ LS : CH
129
+ LT : TR
130
+ LU : MD
131
+ LV : PS
132
+ LW : MK
133
+ LX : GI
134
+ #LY : Serbia (RS) and Montenegro (ME)
135
+ LZ : SK
136
+
137
+ # M - Central America and Mexico
138
+ MB : TC
139
+ MD : DO
140
+ MG : GT
141
+ MH : HN
142
+ MK : JM
143
+ MM : MX
144
+ MN : NI
145
+ MP : PA
146
+ MR : CR
147
+ MS : SV
148
+ MT : HT
149
+ MU : CU
150
+ MW : KY
151
+ MY : BS
152
+ MZ : BZ
153
+
154
+ # N - South Pacific
155
+ NC : CK
156
+ # NF : Fiji (FJ), Tonga (TO)
157
+ # NG : Kiribati (KI) (Gilbert Islands), Tuvalu (TV)
158
+ NI : NU
159
+ NL : WF
160
+ # NS : Samoa (WS), American Samoa (AS)
161
+ NT : PF
162
+ NV : VU
163
+ NW : NC
164
+ # NZ : New Zealand (NZ), Antarctica (AQ)
165
+
166
+ # O - Southwest Asia (excluding Israel and Turkey), Afghanistan and Pakistan
167
+ OA : AF
168
+ OB : BH
169
+ OE : SA
170
+ OI : IR
171
+ OJ : JO
172
+ OK : KW
173
+ OL : LB
174
+ OM : AE
175
+ OO : OM
176
+ OP : PK
177
+ OR : IQ
178
+ OS : SY
179
+ OT : QA
180
+ OY : YE
181
+
182
+ # P - Eastern North Pacific
183
+ PA : US
184
+ # PB : Baker Island
185
+ PC : KI
186
+ PF : US
187
+ PG : GU
188
+ PH : US
189
+ # PJ : Johnston Atoll
190
+ PK : MH
191
+ PL : KI
192
+ # PM : Midway Island
193
+ PO : US
194
+ PP : US
195
+ # PT : Federated States of Micronesia (FM), Palau (PW)
196
+ # PW : Wake Island
197
+
198
+ # R - Western North Pacific
199
+ RC : TW
200
+ RJ : JP
201
+ RK : KR
202
+ RO : JP
203
+ RP : PH
204
+
205
+ # S - South America
206
+ SA : AR
207
+ SB : BR
208
+ SC : CL
209
+ SD : BR
210
+ SE : EC
211
+ SF : FK
212
+ SG : PY
213
+ SK : CO
214
+ SL : BO
215
+ SM : SR
216
+ SN : BR
217
+ SO : GF
218
+ SP : PE
219
+ SS : BR
220
+ SU : UY
221
+ SV : VE
222
+ SW : BR
223
+ SY : GY
224
+
225
+ # T - Caribbean
226
+ TA : AG
227
+ TB : BB
228
+ TD : DM
229
+ TF : GP
230
+ TG : GD
231
+ TI : VI
232
+ TJ : PR
233
+ TK : KN
234
+ TL : LC
235
+ # TN : Netherlands Antilles (AN), Aruba (AW)
236
+ TQ : AI
237
+ TR : MS
238
+ TT : TT
239
+ TU : VG
240
+ TV : VC
241
+ TX : BM
242
+
243
+ # U - Russia and former Soviet States
244
+ UA : KZ
245
+ UB : AZ
246
+ UD : AM
247
+ UG : GE
248
+ UK : UA
249
+ UM : BY
250
+ #UT Tajikistan (TJ), Turkmenistan (TM), Uzbekistan (UZ)
251
+
252
+ # V - South Asia (except Afghanistan and Pakistan) and mainland Southeast Asia
253
+ VA : IN
254
+ VC : LK
255
+ VD : KH
256
+ VE : IN
257
+ VG : BD
258
+ VH : HK
259
+ VI : IN
260
+ VL : LA
261
+ VM : MO
262
+ VN : NP
263
+ VO : IN
264
+ VQ : BT
265
+ VR : MV
266
+ VT : TH
267
+ VV : VN
268
+ VY : MM
269
+
270
+ # W - Maritime Southeast Asia (except the Philippines)
271
+ WA : ID
272
+ # WB : Malaysia (MY), Brunei (BN)
273
+ WI : ID
274
+ WM : MY
275
+ WP : TL
276
+ WQ : ID
277
+ WR : ID
278
+ WS : SG
279
+
280
+ # Z - China, Mongolia and North Korea
281
+ ZK : KP
282
+ ZM : MN
@@ -1,17 +1,200 @@
1
- # first term - weather.com non-standard country_code
2
- # second term - standard country_code
1
+ # first term : weather.com non:standard country_code
2
+ # second term : standard country_code
3
3
  #
4
+ # http://ca.weather.yahoo.com/regional/INTL1.html?More%20World%20Cities
5
+ # http://www.theodora.com/country_digraphs.html
6
+ # http://www.unc.edu/~rowlett/units/codes/country.htm
7
+ #
8
+
9
+ AG : DZ
10
+ AN : AD
11
+ AV : AI
12
+ AY : AQ
13
+ AC : AG
14
+ AA : AW
15
+ ### Ascension Island SH : AC (iana code, not iso code)
4
16
  AS : AU
17
+ AU : AT
18
+ AJ : AZ
19
+
5
20
  BF : BS
6
- CS : CR
7
- CH : CN
21
+ BA : BH
22
+ BG : BD
23
+ BO : BY
24
+ BH : BZ
25
+ BN : BJ
26
+ BD : BM
27
+ BC : BW
28
+ BL : BO
29
+ BK : BA
30
+ BX : BN
31
+ BU : BG
32
+ UV : BF
33
+ BY : BI
34
+ VI : VG
35
+
36
+ CB : KH
37
+ CJ : KY
38
+ CT : CF
39
+ CD : TD
8
40
  CI : CL
9
- EI : IE
41
+ CH : CN
42
+ KT : CX
43
+ CN : KM
44
+ CF : CG
45
+ CG : CD
46
+ CW : CK
47
+ CS : CR
48
+ IV : CI
49
+ EZ : CZ
50
+
51
+ DA : DK
52
+ DJ : DJ
53
+ DO : DM
54
+ DR : DO
55
+
56
+ ES : SV
57
+ EK : GQ
58
+ EN : EE
59
+
60
+ FP : PF
61
+
62
+ GB : GA
63
+ GA : GM
64
+ GG : GE
10
65
  GM : DE
66
+ GJ : GD
67
+ GV : GN
68
+ PU : GW
69
+
70
+ HA : HT
11
71
  HO : HN
72
+
73
+ IC : IS
74
+ IZ : IQ
75
+ EI : IE
12
76
  IS : IL
77
+
13
78
  JA : JP
79
+
80
+ KR : KI
81
+ KN : KP
82
+ KS : KR
83
+ KU : KW
84
+
85
+ LG : LV
86
+ LE : LB
87
+ LS : LI
88
+ LI : LR
89
+ LT : LS
90
+ LH : LT
91
+
92
+ MA : MG
93
+ MI : MW
94
+ MB : MQ
95
+ MP : MU
96
+ MF : YT
97
+ MN : MC
98
+ # Montenegro (YI) : ME
99
+ MO : MA
100
+ BM : MM
101
+ MG : MN
102
+
103
+ WA : NA
104
+ NT : AN
105
+ NU: NI
106
+ NG : NE
107
+ NI : NG
108
+
109
+ WE : PS
110
+ PM : PA
111
+ PP : PG
112
+ PA : PY
113
+ RP : PH
14
114
  PO : PT
15
- SP : ES
115
+
116
+ RS : RU
117
+
118
+ SX : GS
119
+ SC : KN
120
+ ST : LC
121
+ TP : ST
122
+ SG : SN
123
+ # Serbia (YI) : RS
124
+ SE : SC
16
125
  SN : SG
126
+ LO : SK
127
+ BP : SB
128
+ SF : ZA
129
+ SP : ES
130
+ CE: LK
131
+ SU : SD
132
+ NS : SR
133
+ WZ : SZ
134
+ SW : SE
135
+ SZ : CH
136
+
137
+ TI : TJ
138
+ TO : TG
139
+ TN : TO
140
+ TD : TT
141
+ TS : TN
142
+ TU : TR
143
+ TX : TM
144
+ TK : TC
145
+
146
+ UP : UA
147
+ UK : GB
148
+
149
+ NH : VU
150
+ VM: VN
151
+
152
+ WI : EH
153
+
154
+ YM : YE
155
+
156
+ ZA : ZM
157
+ ZI : ZW
158
+
159
+ # Aland Islands : AX
160
+ # Bouvet Island : BV
161
+ # British Indian Ocean Territory : IO
162
+ # Cocos (Keeling) Islands : CC
163
+ # East Timor : TL
164
+ # Faroe Islands : FO
165
+ # France, Metropolitan : FX
166
+ # French Southern Territories : TF
167
+ # Great Britain (UK) : GB
168
+ # Heard and McDonald Islands : HM
169
+ # Hong Kong : HK
170
+ # Jersey : JE
171
+ # Macau : MO
172
+ # Montserrat : MS
173
+ # Neutral Zone : NT
174
+ # Niue : NU
175
+ # Norfolk Island : NF
176
+ # Oman : OM
177
+ # Pitcairn : PN
178
+ # Saint Vincent & the Grenadines : VC
179
+ # Samoa : WS
180
+ # St. Helena : SH
181
+ # St. Pierre and Miquelon : PM
182
+ # Svalbard & Jan Mayen Islands : SJ
183
+ # Tokelau : TK
184
+ # US Minor Outlying Islands : UM
185
+ # USSR (former) : SU
186
+ # Vatican City State (Holy See) : VA
187
+ # Wallis and Futuna Islands : WF
188
+ # Yugoslavia (former) : YU
189
+ # (ZR : Zaire) : See CD Congo, Democratic Republic
17
190
 
191
+ # four letter codes
192
+ ### USWQ : ??? Wake Island
193
+ ### Virgin Islands (U.S.) USVI : VI
194
+ ### Puerto Rico USPR : PR
195
+ ### Northern Mariana Islands USMP : MP
196
+ ### Micronesia USFM : FM
197
+ ### Marshall Islands USMH : MH
198
+ ### American Samoa USAS : AS
199
+ ### Palau USPW : PW
200
+ ### Guam USGU : GU