metar-parser 1.1.7 → 1.1.8

Sign up to get free protection for your applications and to get access to all the features.
data/lib/metar/parser.rb CHANGED
@@ -124,10 +124,11 @@ module Metar
124
124
  when @chunks[0] == 'AUTO' # WMO 15.4
125
125
  @chunks.shift
126
126
  @observer = :auto
127
- when @chunks[0] == 'COR'
127
+ when @chunks[0] == 'COR' # WMO specified code word for correction
128
128
  @chunks.shift
129
129
  @observer = :corrected
130
- when @chunks[0] == 'CCA'
130
+ when @chunks[0] =~ /CC[A-Z]/ # Canadian correction
131
+ # Canada uses CCA for first correction, CCB for second, etc...
131
132
  @chunks.shift
132
133
  @observer = :corrected
133
134
  when @chunks[0] == 'RTD' # Delayed observation, no comments on observer
data/lib/metar/version.rb CHANGED
@@ -2,7 +2,7 @@ module Metar
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 1
4
4
  MINOR = 1
5
- TINY = 7
5
+ TINY = 8
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -11,12 +11,4 @@ describe I18n do
11
11
  expect(I18n.load_path).to include(italian_path)
12
12
  expect(I18n.load_path).to include(german_path)
13
13
  end
14
-
15
- it 'falls back to the language translation when a region-specific translation is not available' do
16
- old_locale = I18n.locale
17
- I18n.locale = :'en-FOO'
18
- expect(I18n.t('metar.altitude.at')).to eq('at')
19
- I18n.locale = old_locale
20
- end
21
14
  end
22
-
@@ -92,11 +92,23 @@ describe Metar::Parser do
92
92
  expect(parser.observer).to eq(:corrected)
93
93
  end
94
94
 
95
- it 'corrected (Canadian)' do
95
+ it 'corrected (Canadian, first correction)' do
96
96
  parser = setup_parser('CYZU 310100Z CCA 26004KT 15SM FEW009 BKN040TCU BKN100 OVC210 15/12 A2996 RETS RMK SF1TCU4AC2CI1 SLP149')
97
97
 
98
98
  expect(parser.observer).to eq(:corrected)
99
99
  end
100
+
101
+ it 'corrected (Canadian, second correction)' do
102
+ parser = setup_parser('CYCX 052000Z CCB 30014G27KT 15SM DRSN SCT035 M02/M09 A2992 RMK SC4 SLP133')
103
+
104
+ expect(parser.observer).to eq(:corrected)
105
+ end
106
+
107
+ it 'corrected (Canadian, rare third correction)' do
108
+ parser = setup_parser('CYEG 120000Z CCC 12005KT 15SM FEW110 BKN190 03/M01 A2980 RMK AC2AC3 SLP122')
109
+
110
+ expect(parser.observer).to eq(:corrected)
111
+ end
100
112
  end
101
113
 
102
114
  it 'wind' do
@@ -1,144 +1,110 @@
1
1
  # encoding: utf-8
2
- load File.expand_path( '../spec_helper.rb', File.dirname(__FILE__) )
2
+ require 'spec_helper'
3
3
 
4
4
  require 'net/ftp'
5
5
  require 'time'
6
6
 
7
7
  module MetarRawTestHelper
8
-
9
- def noaa_metar
10
- raw_time = "2010/02/15 10:20"
11
- "#{ raw_time }\n#{ raw_metar }"
12
- end
13
-
14
8
  def raw_metar
15
9
  "ESSB 151020Z 26003KT 2000 R12/1000N R30/1500N VV002 M07/M07 Q1013 1271//55"
16
10
  end
17
-
18
11
  end
19
12
 
20
13
  describe Metar::Raw::Data do
21
-
22
14
  include MetarRawTestHelper
23
15
 
24
16
  context 'initialization' do
17
+ let(:call_time) { Time.parse('2012-07-29 16:35') }
25
18
 
26
19
  it 'should parse data, if supplied' do
27
- @call_time = Time.parse('2012-07-29 16:35')
28
- Time.stub!(:now).and_return(@call_time)
20
+ now = call_time
21
+ Time.stub(:now) { now }
29
22
 
30
23
  raw = Metar::Raw::Data.new(raw_metar)
31
24
 
32
- raw.metar. should == raw_metar
33
- raw.cccc. should == 'ESSB'
34
- raw.time. should == @call_time
25
+ expect(raw.metar).to eq(raw_metar)
26
+ expect(raw.cccc).to eq('ESSB')
27
+ expect(raw.time).to eq(call_time)
35
28
  end
36
-
37
29
  end
38
-
39
30
  end
40
31
 
41
32
  describe Metar::Raw::Noaa do
42
-
43
33
  include MetarRawTestHelper
44
34
 
35
+ let(:ftp) { double('ftp', :login => nil, :chdir => nil, :passive= => nil, :retrbinary => nil) }
36
+
37
+ before do
38
+ Net::FTP.stub(:new).and_return(ftp)
39
+ end
40
+
45
41
  after :each do
46
- Metar::Raw::Noaa.send( :class_variable_set, '@@connection', nil )
42
+ Metar::Raw::Noaa.send(:class_variable_set, '@@connection', nil)
47
43
  end
48
44
 
49
45
  context '.connection' do
50
-
51
46
  context 'uncached' do
52
-
53
47
  it 'sets up the connection' do
54
- ftp = stub( 'ftp', :login => nil, :chdir => nil, :passive= => nil )
55
-
56
- Net::FTP. should_receive( :new ).
57
- and_return( ftp )
58
-
59
48
  Metar::Raw::Noaa.connect
60
- end
61
49
 
50
+ expect(Net::FTP).to have_received(:new)
51
+ end
62
52
  end
63
53
 
64
54
  context 'cached' do
65
-
66
55
  before :each do
67
- @ftp = stub( 'ftp' )
68
- Metar::Raw::Noaa.send( :class_variable_set, '@@connection', @ftp )
56
+ Metar::Raw::Noaa.send(:class_variable_set, '@@connection', ftp)
69
57
  end
70
58
 
71
59
  it 'does not connect to FTP' do
72
- Net::FTP. should_not_receive( :new )
73
-
74
60
  Metar::Raw::Noaa.connection
61
+
62
+ expect(Net::FTP).to_not have_received(:new)
75
63
  end
76
64
 
77
65
  it 'returns the cached connection' do
78
66
  connection = Metar::Raw::Noaa.connection
79
67
 
80
- connection. should == @ftp
68
+ expect(connection).to eq(ftp)
81
69
  end
82
-
83
70
  end
84
-
85
71
  end
86
72
 
87
73
  context '.connect' do
88
-
89
74
  it 'sets up the connection' do
90
- ftp = stub( 'ftp' )
91
-
92
- Net::FTP. should_receive( :new ).
93
- and_return( ftp )
94
- ftp. should_receive( :login )
95
- ftp. should_receive( :chdir )
96
- ftp. should_receive( :passive= ).
97
- with( true )
98
-
99
75
  Metar::Raw::Noaa.connect
100
- end
101
76
 
77
+ expect(Net::FTP).to have_received(:new)
78
+ expect(ftp).to have_received(:login).with()
79
+ expect(ftp).to have_received(:chdir).with('data/observations/metar/stations')
80
+ expect(ftp).to have_received(:passive=).with(true)
81
+ end
102
82
  end
103
83
 
104
84
  context '.fetch' do
105
-
106
85
  it 'uses the connection' do
107
- ftp = stub( 'ftp', :login => nil, :chdir => nil, :passive= => nil, :retrbinary => nil )
108
-
109
- Net::FTP. should_receive( :new ).
110
- and_return( ftp )
86
+ Metar::Raw::Noaa.fetch('the_cccc')
111
87
 
112
- Metar::Raw::Noaa.fetch( 'the_cccc' )
88
+ expect(Net::FTP).to have_received(:new)
113
89
  end
114
90
 
115
91
  it 'downloads the raw report' do
116
- ftp = stub( 'ftp', :login => nil, :chdir => nil, :passive= => nil )
117
- Net::FTP.stub!( :new ).and_return( ftp )
118
-
119
- ftp. should_receive( :retrbinary ) do | *args, &block |
120
- args[ 0 ]. should == 'RETR the_cccc.TXT'
121
- args[ 1 ]. should be_a Fixnum
122
- end
92
+ Metar::Raw::Noaa.fetch('the_cccc')
123
93
 
124
- Metar::Raw::Noaa.fetch( 'the_cccc' )
94
+ expect(ftp).to have_received(:retrbinary).with('RETR the_cccc.TXT', kind_of(Fixnum))
125
95
  end
126
96
 
127
97
  it 'returns the data' do
128
- ftp = stub( 'ftp', :login => nil, :chdir => nil, :passive= => nil )
129
- def ftp.retrbinary( *args, &block )
98
+ def ftp.retrbinary(*args, &block)
130
99
  block.call "chunk 1\n"
131
100
  block.call "chunk 2\n"
132
101
  end
133
- Net::FTP.stub!( :new ).and_return( ftp )
134
-
135
- raw = Metar::Raw::Noaa.fetch( 'the_cccc' )
102
+ raw = Metar::Raw::Noaa.fetch('the_cccc')
136
103
 
137
- raw. should == "chunk 1\nchunk 2\n"
104
+ expect(raw).to eq("chunk 1\nchunk 2\n")
138
105
  end
139
106
 
140
107
  it 'retries retrieval once' do
141
- ftp = stub( 'ftp', :login => nil, :chdir => nil, :passive= => nil )
142
108
  def ftp.attempt
143
109
  @attempt
144
110
  end
@@ -146,21 +112,19 @@ describe Metar::Raw::Noaa do
146
112
  @attempt = a
147
113
  end
148
114
  ftp.attempt = 0
149
- def ftp.retrbinary( *args, &block )
115
+ def ftp.retrbinary(*args, &block)
150
116
  self.attempt = self.attempt + 1
151
117
  raise Net::FTPTempError if self.attempt == 1
152
118
  block.call "chunk 1\n"
153
119
  block.call "chunk 2\n"
154
120
  end
155
- Net::FTP.stub!( :new ).and_return( ftp )
156
121
 
157
- raw = Metar::Raw::Noaa.fetch( 'the_cccc' )
122
+ raw = Metar::Raw::Noaa.fetch('the_cccc')
158
123
 
159
- raw. should == "chunk 1\nchunk 2\n"
124
+ expect(raw).to eq("chunk 1\nchunk 2\n")
160
125
  end
161
126
 
162
127
  it 'fails with an error, if retrieval fails twice' do
163
- ftp = stub( 'ftp', :login => nil, :chdir => nil, :passive= => nil )
164
128
  def ftp.attempt
165
129
  @attempt
166
130
  end
@@ -168,51 +132,55 @@ describe Metar::Raw::Noaa do
168
132
  @attempt = a
169
133
  end
170
134
  ftp.attempt = 0
171
- def ftp.retrbinary( *args, &block )
135
+ def ftp.retrbinary(*args, &block)
172
136
  self.attempt = self.attempt + 1
173
137
  raise Net::FTPTempError
174
138
  end
175
- Net::FTP.stub!( :new ).and_return( ftp )
176
139
 
177
140
  expect do
178
- Metar::Raw::Noaa.fetch( 'the_cccc' )
179
- end. to raise_error( RuntimeError, /failed 2 times/)
141
+ Metar::Raw::Noaa.fetch('the_cccc')
142
+ end.to raise_error(RuntimeError, /failed 2 times/)
180
143
  end
181
-
182
144
  end
183
145
 
184
146
  context 'initialization' do
185
-
186
147
  it 'should accept CCCC codes' do
187
- raw = Metar::Raw::Noaa.new( 'XXXX' )
148
+ raw = Metar::Raw::Noaa.new('XXXX')
188
149
 
189
- raw.cccc. should == 'XXXX'
150
+ expect(raw.cccc).to eq('XXXX')
190
151
  end
191
152
 
192
153
  it 'should accept Stations' do
193
- station = stub( 'Metar::Station', :cccc => 'YYYY' )
194
- raw = Metar::Raw::Noaa.new( station )
154
+ station = double('Metar::Station', :cccc => 'YYYY')
155
+ raw = Metar::Raw::Noaa.new(station)
195
156
 
196
- raw.cccc. should == 'YYYY'
157
+ expect(raw.cccc).to eq('YYYY')
197
158
  end
198
-
199
159
  end
200
160
 
201
161
  context 'lazy loading' do
202
-
203
- it 'should fetch data on demand' do
204
- raw = Metar::Raw::Noaa.new( 'ESSB' )
162
+ let(:noaa_metar) do
163
+ raw_time = "2010/02/15 10:20"
164
+ "#{raw_time}\n#{raw_metar}"
165
+ end
166
+
167
+ before do
168
+ Metar::Raw::Noaa.stub(:fetch => noaa_metar)
169
+ end
205
170
 
206
- Metar::Raw::Noaa. should_receive(:fetch).
207
- with( 'ESSB' ).
208
- and_return(noaa_metar)
171
+ subject { Metar::Raw::Noaa.new('ESSB') }
209
172
 
210
- raw.metar
173
+ it 'should fetch data on demand' do
174
+ subject.metar
211
175
 
212
- raw.data. should == noaa_metar
176
+ expect(Metar::Raw::Noaa).to have_received(:fetch).with('ESSB')
213
177
  end
214
178
 
215
- end
179
+ it 'sets data to the returned value' do
180
+ subject.metar
216
181
 
182
+ expect(subject.data).to eq(noaa_metar)
183
+ end
184
+ end
217
185
  end
218
186
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metar-parser
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 3
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 1
9
- - 7
10
- version: 1.1.7
9
+ - 8
10
+ version: 1.1.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Joe Yates
@@ -15,11 +15,11 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-09-03 00:00:00 +02:00
18
+ date: 2015-04-13 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- requirement: &id001 !ruby/object:Gem::Requirement
22
+ version_requirements: &id001 !ruby/object:Gem::Requirement
23
23
  none: false
24
24
  requirements:
25
25
  - - ">="
@@ -28,12 +28,12 @@ dependencies:
28
28
  segments:
29
29
  - 0
30
30
  version: "0"
31
- version_requirements: *id001
32
- name: rake
33
31
  prerelease: false
32
+ requirement: *id001
33
+ name: rake
34
34
  type: :runtime
35
35
  - !ruby/object:Gem::Dependency
36
- requirement: &id002 !ruby/object:Gem::Requirement
36
+ version_requirements: &id002 !ruby/object:Gem::Requirement
37
37
  none: false
38
38
  requirements:
39
39
  - - ">="
@@ -42,12 +42,12 @@ dependencies:
42
42
  segments:
43
43
  - 0
44
44
  version: "0"
45
- version_requirements: *id002
46
- name: rdoc
47
45
  prerelease: false
46
+ requirement: *id002
47
+ name: rdoc
48
48
  type: :runtime
49
49
  - !ruby/object:Gem::Dependency
50
- requirement: &id003 !ruby/object:Gem::Requirement
50
+ version_requirements: &id003 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ">="
@@ -58,12 +58,20 @@ dependencies:
58
58
  - 3
59
59
  - 5
60
60
  version: 0.3.5
61
- version_requirements: *id003
62
- name: i18n
61
+ - - <
62
+ - !ruby/object:Gem::Version
63
+ hash: 3
64
+ segments:
65
+ - 0
66
+ - 7
67
+ - 0
68
+ version: 0.7.0
63
69
  prerelease: false
70
+ requirement: *id003
71
+ name: i18n
64
72
  type: :runtime
65
73
  - !ruby/object:Gem::Dependency
66
- requirement: &id004 !ruby/object:Gem::Requirement
74
+ version_requirements: &id004 !ruby/object:Gem::Requirement
67
75
  none: false
68
76
  requirements:
69
77
  - - ~>
@@ -74,28 +82,28 @@ dependencies:
74
82
  - 3
75
83
  - 1
76
84
  version: 0.3.1
77
- version_requirements: *id004
78
- name: m9t
79
85
  prerelease: false
86
+ requirement: *id004
87
+ name: m9t
80
88
  type: :runtime
81
89
  - !ruby/object:Gem::Dependency
82
- requirement: &id005 !ruby/object:Gem::Requirement
90
+ version_requirements: &id005 !ruby/object:Gem::Requirement
83
91
  none: false
84
92
  requirements:
85
- - - ">="
93
+ - - ~>
86
94
  - !ruby/object:Gem::Version
87
- hash: 35
95
+ hash: 53
88
96
  segments:
89
97
  - 2
90
- - 11
91
- - 0
92
- version: 2.11.0
93
- version_requirements: *id005
94
- name: rspec
98
+ - 14
99
+ - 1
100
+ version: 2.14.1
95
101
  prerelease: false
102
+ requirement: *id005
103
+ name: rspec
96
104
  type: :development
97
105
  - !ruby/object:Gem::Dependency
98
- requirement: &id006 !ruby/object:Gem::Requirement
106
+ version_requirements: &id006 !ruby/object:Gem::Requirement
99
107
  none: false
100
108
  requirements:
101
109
  - - ">="
@@ -104,12 +112,12 @@ dependencies:
104
112
  segments:
105
113
  - 0
106
114
  version: "0"
107
- version_requirements: *id006
108
- name: rcov
109
115
  prerelease: false
116
+ requirement: *id006
117
+ name: rcov
110
118
  type: :development
111
119
  - !ruby/object:Gem::Dependency
112
- requirement: &id007 !ruby/object:Gem::Requirement
120
+ version_requirements: &id007 !ruby/object:Gem::Requirement
113
121
  none: false
114
122
  requirements:
115
123
  - - ">="
@@ -118,12 +126,12 @@ dependencies:
118
126
  segments:
119
127
  - 0
120
128
  version: "0"
121
- version_requirements: *id007
122
- name: pry
123
129
  prerelease: false
130
+ requirement: *id007
131
+ name: pry
124
132
  type: :development
125
133
  - !ruby/object:Gem::Dependency
126
- requirement: &id008 !ruby/object:Gem::Requirement
134
+ version_requirements: &id008 !ruby/object:Gem::Requirement
127
135
  none: false
128
136
  requirements:
129
137
  - - ">="
@@ -132,11 +140,11 @@ dependencies:
132
140
  segments:
133
141
  - 0
134
142
  version: "0"
135
- version_requirements: *id008
136
- name: pry-doc
137
143
  prerelease: false
144
+ requirement: *id008
145
+ name: pry-doc
138
146
  type: :development
139
- description: " metar-parser is a ruby gem that downloads weather reports, parses them and formats reports.\n\n It also provides weather station listings and info (e.g. country, latitude and longitude).\n\n Reports can be fully localized (currently English and Italian are available).\n"
147
+ description: " metar-parser is a ruby gem that downloads weather reports, parses them and formats reports.\n\n It also provides weather station listings and info (e.g. country, latitude and longitude).\n\n Reports can be fully localized (currently Brazilian Portuguese, English, German and Italian are available).\n"
140
148
  email: joe.g.yates@gmail.com
141
149
  executables: []
142
150
 
@@ -149,34 +157,34 @@ files:
149
157
  - COPYING
150
158
  - Rakefile
151
159
  - bin/parse_raw.rb
160
+ - lib/metar.rb
152
161
  - lib/metar/parser.rb
153
- - lib/metar/report.rb
154
162
  - lib/metar/raw.rb
155
163
  - lib/metar/station.rb
156
164
  - lib/metar/data.rb
165
+ - lib/metar/report.rb
157
166
  - lib/metar/version.rb
158
- - lib/metar.rb
159
167
  - spec/spec_helper.rb
160
- - spec/unit/report_spec.rb
161
- - spec/unit/pressure_spec.rb
162
- - spec/unit/station_spec.rb
163
- - spec/unit/visibility_spec.rb
164
- - spec/unit/sky_condition_spec.rb
165
- - spec/unit/speed_spec.rb
166
- - spec/unit/wind_spec.rb
167
- - spec/unit/distance_spec.rb
168
+ - spec/unit/runway_visible_range_spec.rb
169
+ - spec/unit/weather_phenomenon_spec.rb
168
170
  - spec/unit/temperature_spec.rb
169
171
  - spec/unit/i18n_spec.rb
170
- - spec/unit/vertical_visibility_spec.rb
172
+ - spec/unit/pressure_spec.rb
171
173
  - spec/unit/remark_spec.rb
172
- - spec/unit/runway_visible_range_spec.rb
173
- - spec/unit/weather_phenomenon_spec.rb
174
- - spec/unit/raw_spec.rb
174
+ - spec/unit/speed_spec.rb
175
+ - spec/unit/vertical_visibility_spec.rb
175
176
  - spec/unit/parser_spec.rb
177
+ - spec/unit/visibility_spec.rb
178
+ - spec/unit/report_spec.rb
179
+ - spec/unit/raw_spec.rb
180
+ - spec/unit/distance_spec.rb
181
+ - spec/unit/wind_spec.rb
182
+ - spec/unit/sky_condition_spec.rb
183
+ - spec/unit/station_spec.rb
176
184
  - spec/unit/variable_wind_spec.rb
177
- - locales/en.yml
178
185
  - locales/it.yml
179
186
  - locales/pt-BR.yml
187
+ - locales/en.yml
180
188
  - locales/de.yml
181
189
  has_rdoc: true
182
190
  homepage: http://github.com/joeyates/metar-parser
@@ -213,20 +221,20 @@ signing_key:
213
221
  specification_version: 3
214
222
  summary: A Ruby gem for worldwide weather reports
215
223
  test_files:
216
- - spec/unit/report_spec.rb
217
- - spec/unit/pressure_spec.rb
218
- - spec/unit/station_spec.rb
219
- - spec/unit/visibility_spec.rb
220
- - spec/unit/sky_condition_spec.rb
221
- - spec/unit/speed_spec.rb
222
- - spec/unit/wind_spec.rb
223
- - spec/unit/distance_spec.rb
224
+ - spec/unit/runway_visible_range_spec.rb
225
+ - spec/unit/weather_phenomenon_spec.rb
224
226
  - spec/unit/temperature_spec.rb
225
227
  - spec/unit/i18n_spec.rb
226
- - spec/unit/vertical_visibility_spec.rb
228
+ - spec/unit/pressure_spec.rb
227
229
  - spec/unit/remark_spec.rb
228
- - spec/unit/runway_visible_range_spec.rb
229
- - spec/unit/weather_phenomenon_spec.rb
230
- - spec/unit/raw_spec.rb
230
+ - spec/unit/speed_spec.rb
231
+ - spec/unit/vertical_visibility_spec.rb
231
232
  - spec/unit/parser_spec.rb
233
+ - spec/unit/visibility_spec.rb
234
+ - spec/unit/report_spec.rb
235
+ - spec/unit/raw_spec.rb
236
+ - spec/unit/distance_spec.rb
237
+ - spec/unit/wind_spec.rb
238
+ - spec/unit/sky_condition_spec.rb
239
+ - spec/unit/station_spec.rb
232
240
  - spec/unit/variable_wind_spec.rb