metar-parser 0.9.11 → 0.9.12

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.
@@ -0,0 +1,37 @@
1
+ load File.expand_path( '../spec_helper.rb', File.dirname(__FILE__) )
2
+ # encoding: utf-8
3
+
4
+ RSpec::Matchers.define :be_distance do | expected |
5
+ match do | distance |
6
+ if distance.nil? && expected == :expect_nil
7
+ true
8
+ elsif distance.nil? && expected != :expect_nil
9
+ false
10
+ elsif distance.value.nil? && expected.nil?
11
+ true
12
+ elsif ( distance.value - expected ).abs > 0.01
13
+ false
14
+ else
15
+ true
16
+ end
17
+ end
18
+ end
19
+
20
+ describe Metar::VerticalVisibility do
21
+
22
+ context '.parse' do
23
+
24
+ [
25
+ [ 'VV + nnn', 'VV300', 9000 ],
26
+ [ '///', '///', nil ],
27
+ [ 'returns nil for unmatched', 'FUBAR', :expect_nil ],
28
+ ].each do | docstring, raw, expected |
29
+ example docstring do
30
+ Metar::VerticalVisibility.parse( raw ).should be_distance( expected )
31
+ end
32
+ end
33
+
34
+ end
35
+
36
+ end
37
+
@@ -0,0 +1,84 @@
1
+ load File.expand_path( '../spec_helper.rb', File.dirname(__FILE__) )
2
+ # encoding: utf-8
3
+
4
+ RSpec::Matchers.define :be_visibility do | distance, direction, comparator |
5
+ match do | visibility |
6
+ if visibility.nil? && [ distance, direction, comparator ].all?( &:nil? )
7
+ true
8
+ elsif visibility.nil? != [ distance, direction, comparator ].all?( &:nil? )
9
+ false
10
+ elsif visibility.distance.nil? != distance.nil?
11
+ false
12
+ elsif visibility.direction.nil? != direction.nil?
13
+ false
14
+ elsif visibility.comparator.nil? != comparator.nil?
15
+ false
16
+ elsif visibility.distance.is_a?( Metar::Distance ) && (visibility.distance.value - distance).abs > 0.01
17
+ false
18
+ elsif visibility.direction.is_a?( M9t::Direction ) && (visibility.direction.value - direction).abs > 0.01
19
+ false
20
+ elsif comparator.is_a?( Symbol ) && visibility.comparator != comparator
21
+ false
22
+ else
23
+ true
24
+ end
25
+ end
26
+ end
27
+
28
+ describe Metar::Visibility do
29
+
30
+ context '.parse' do
31
+
32
+ [
33
+ [ 'understands 9999', '9999', [ 10000.00, nil, :more_than ] ],
34
+ [ 'understands nnnn + NDV', '0123NDV', [ 123.00, nil, nil ] ],
35
+ [ 'understands n/nSM', '3/4SM', [ 1207.01, nil, nil ] ],
36
+ [ 'understands n n/nSM', '1 1/4SM', [ 2011.68, nil, nil ] ],
37
+ [ 'understands nSM', '5SM', [ 8046.72, nil, nil ] ],
38
+ [ 'understands M1/4SM', 'M1/4SM', [ 402.34, nil, :less_than ] ],
39
+ [ 'understands n + KM', '5KM', [ 5000.00, nil, nil ] ],
40
+ [ 'understands n', '5', [ 5000.00, nil, nil ] ],
41
+ [ 'understands n + compass', '5NW', [ 5000.00, 315.0, nil ] ],
42
+ [ 'returns nil for unmatched', 'FUBAR', [ nil, nil, nil ] ],
43
+ ].each do | docstring, raw, expected |
44
+ example docstring do
45
+ Metar::Visibility.parse( raw ).should be_visibility( *expected )
46
+ end
47
+ end
48
+
49
+ end
50
+
51
+ context '#to_s' do
52
+
53
+ before :each do
54
+ @locale = I18n.locale
55
+ I18n.locale = :it
56
+ end
57
+
58
+ after :each do
59
+ I18n.locale = @locale
60
+ end
61
+
62
+ [
63
+ [ 'with distance', :en, [ :set, nil, nil ], '4km' ],
64
+ [ 'with distance and direction', :en, [ :set, :set, nil ], '4km ESE' ],
65
+ [ 'with distance and comparator', :en, [ :set, nil, :less_than ], 'less than 4km' ],
66
+ [ 'with distance, direction and comparator', :en, [ :set, :set, :more_than ], 'more than 4km ESE' ],
67
+ [ 'with distance and direction', :it, [ :set, :set, nil ], '4km ESE' ],
68
+ [ 'with distance, direction and comparator', :it, [ :set, :set, :more_than ], 'piú di 4km ESE' ],
69
+ ].each do | docstring, locale, ( distance, direction, comparator ), expected |
70
+ distance = Metar::Distance.new( 4321 ) if distance == :set
71
+ direction = M9t::Direction.new( 123 ) if direction == :set
72
+
73
+ example docstring + " (#{locale})" do
74
+ I18n.locale = locale
75
+
76
+ Metar::Visibility.new( distance, direction, comparator ).to_s.
77
+ should == expected
78
+ end
79
+ end
80
+
81
+ end
82
+
83
+ end
84
+
@@ -0,0 +1,68 @@
1
+ load File.expand_path( '../spec_helper.rb', File.dirname(__FILE__) )
2
+ # encoding: utf-8
3
+
4
+ RSpec::Matchers.define :be_weather_phenomenon do | modifier, descriptor, phenomenon |
5
+ match do | wp |
6
+ if wp.nil? && phenomenon.nil?
7
+ true
8
+ elsif wp.nil? != phenomenon.nil?
9
+ false
10
+ elsif wp.phenomenon != phenomenon
11
+ false
12
+ elsif wp.modifier != modifier
13
+ false
14
+ elsif wp.descriptor != descriptor
15
+ false
16
+ else
17
+ true
18
+ end
19
+ end
20
+ end
21
+
22
+ describe Metar::WeatherPhenomenon do
23
+
24
+ context '.parse' do
25
+
26
+ [
27
+ [ 'simple phenomenon', 'BR', [ nil, nil, 'mist' ] ],
28
+ [ 'descriptor + phenomenon', 'BCFG', [ nil, 'patches of', 'fog' ] ],
29
+ [ 'modifier + phenomenon', '+RA', [ 'heavy', nil, 'rain' ] ],
30
+ [ 'modifier + descriptor + phenomenon', 'VCDRFG', [ 'nearby', 'low drifting', 'fog' ] ],
31
+ [ 'returns nil for unmatched', 'FUBAR', [ nil, nil, nil ] ],
32
+ ].each do | docstring, raw, expected |
33
+ example docstring do
34
+ Metar::WeatherPhenomenon.parse( raw ).should be_weather_phenomenon( *expected )
35
+ end
36
+ end
37
+
38
+ end
39
+
40
+ context '#to_s' do
41
+
42
+ before :all do
43
+ @locale = I18n.locale
44
+ I18n.locale = :it
45
+ end
46
+
47
+ after :all do
48
+ I18n.locale = @locale
49
+ end
50
+
51
+ [
52
+ [ 'simple phenomenon', :en, [ nil, nil, 'mist' ], 'mist' ],
53
+ [ 'simple phenomenon', :it, [ nil, nil, 'mist' ], 'foschia' ],
54
+ [ 'descriptor + phenomenon', :en, [ nil, 'patches of', 'fog' ], 'patches of fog' ],
55
+ [ 'modifier + phenomenon', :en, ['heavy', nil, 'drizzle' ], 'heavy drizzle' ],
56
+ [ 'modifier + descriptor + phenomenon', :en, ['heavy', 'freezing', 'drizzle' ], 'heavy freezing drizzle' ],
57
+ ].each do | docstring, locale, ( modifier, descriptor, phenomenon ), expected |
58
+ example docstring + " (#{locale})" do
59
+ I18n.locale = locale
60
+ Metar::WeatherPhenomenon.new( phenomenon, modifier, descriptor ).to_s.
61
+ should == expected
62
+ end
63
+ end
64
+
65
+ end
66
+
67
+ end
68
+
@@ -0,0 +1,99 @@
1
+ load File.expand_path( '../spec_helper.rb', File.dirname(__FILE__) )
2
+ # encoding: utf-8
3
+
4
+ RSpec::Matchers.define :be_wind do | direction, speed, gusts |
5
+ match do | wind |
6
+ if wind.nil? && [ direction, speed, gusts ].all?( &:nil? )
7
+ true
8
+ elsif wind.direction.nil? != direction.nil?
9
+ false
10
+ elsif wind.speed.nil? != speed.nil?
11
+ false
12
+ elsif wind.gusts.nil? != gusts.nil?
13
+ false
14
+ elsif direction.is_a?( Symbol ) && wind.direction != direction
15
+ false
16
+ elsif direction.is_a?( M9t::Direction ) && (wind.direction.value - direction).abs > 0.01
17
+ false
18
+ elsif speed.is_a?( Symbol ) && wind.speed != speed
19
+ false
20
+ elsif speed.is_a?( Metar::Speed ) && (wind.speed.value - speed).abs > 0.01
21
+ false
22
+ elsif ! wind.gusts.nil? && (wind.gusts.value - gusts).abs > 0.01
23
+ false
24
+ else
25
+ true
26
+ end
27
+ end
28
+ end
29
+
30
+ describe Metar::Wind do
31
+
32
+ context '.parse' do
33
+
34
+ [
35
+ [ 'treats 5 digits as degrees and kilometers per hour', '12345', [ 123.0, 12.50, nil ] ],
36
+ [ 'understands 5 digits + KMH', '12345KMH', [ 123.0, 12.50, nil ] ],
37
+ [ 'understands 5 digits + MPS', '12345MPS', [ 123.0, 45.00, nil ] ],
38
+ [ 'understands 5 digits + KT', '12345KT', [ 123.0, 23.15, nil ] ],
39
+ [ 'returns nil for directions outside 0 to 360', '88845KT', [ nil, nil, nil ] ],
40
+ [ 'understands 5 digits + G + 2 digits', '12345G67', [ 123.0, 12.50, 18.61 ] ],
41
+ [ 'understands 5 digits + G + 2 digits + MPS', '12345G67MPS', [ 123.0, 45.00, 67.00 ] ],
42
+ [ 'understands 5 digits + G + 2 digits + KMH', '12345G67KMH', [ 123.0, 12.50, 18.61 ] ],
43
+ [ 'understands 5 digits + G + 2 digits + KT', '12345G67KT', [ 123.0, 23.15, 34.47 ] ],
44
+ [ 'understands VRB + 2 digits' 'VRB12', [ :variable_direction, 3.33, nil ] ],
45
+ [ 'understands VRB + 2 digits + KMH', 'VRB12KMH', [ :variable_direction, 3.33, nil ] ],
46
+ [ 'understands VRB + 2 digits + MPS', 'VRB12MPS', [ :variable_direction, 12.00, nil ] ],
47
+ [ 'understands VRB + 2 digits + KT', 'VRB12KT', [ :variable_direction, 6.17, nil ] ],
48
+ [ 'understands /// + 2 digits', '///12', [ :unknown_direction, 3.33, nil ] ],
49
+ [ 'understands /// + 2 digits + KMH', '///12KMH', [ :unknown_direction, 3.33, nil ] ],
50
+ [ 'understands /// + 2 digits + MPS', '///12MPS', [ :unknown_direction, 12.00, nil ] ],
51
+ [ 'understands /// + 2 digits + KT', '///12KT', [ :unknown_direction, 6.17, nil ] ],
52
+ [ 'understands /////', '/////', [ :unknown_direction, :unknown_speed, nil ] ],
53
+ [ 'returns nil for badly formatted values', 'XYZ12KT', [ nil, nil, nil ] ],
54
+ [ 'returns nil for nil', nil, [ nil, nil, nil ] ],
55
+ ].each do | docstring, raw, expected |
56
+ example docstring do
57
+ Metar::Wind.parse( raw ).should be_wind( *expected )
58
+ end
59
+ end
60
+
61
+ end
62
+
63
+ context '#to_s' do
64
+
65
+ before :each do
66
+ @locale = I18n.locale
67
+ I18n.locale = :it
68
+ end
69
+
70
+ after :each do
71
+ I18n.locale = @locale
72
+ end
73
+
74
+ [
75
+ [ 'should format speed and direction', :en, [ nil, nil, nil ], '443km/h ESE' ],
76
+ [ 'should handle variable_direction', :en, [ :variable_direction, nil, nil ], '443km/h variable direction' ],
77
+ [ 'should handle unknown_direction', :en, [ :unknown_direction, nil, nil ], '443km/h unknown direction' ],
78
+ [ 'should handle unknown_speed', :en, [ nil, :unknown_speed, nil ], 'unknown speed ESE' ],
79
+ [ 'should include gusts', :en, [ nil, nil, Metar::Speed.new( 123 ) ], '443km/h ESE gusts 443km/h' ],
80
+ [ 'should format speed and direction', :it, [ nil, nil, nil ], '443km/h ESE' ],
81
+ [ 'should handle variable_direction', :it, [ :variable_direction, nil, nil ], '443km/h direzione variabile' ],
82
+ [ 'should handle unknown_direction', :it, [ :unknown_direction, nil, nil ], '443km/h direzione sconosciuta' ],
83
+ [ 'should handle unknown_speed', :it, [ nil, :unknown_speed, nil ], 'velocità sconosciuta ESE' ],
84
+ [ 'should include gusts', :it, [ nil, nil, Metar::Speed.new( 123 ) ], '443km/h ESE folate di 443km/h' ],
85
+ ].each do | docstring, locale, ( direction, speed, gusts ), expected |
86
+ direction ||= M9t::Direction.new( 123 )
87
+ speed ||= Metar::Speed.new( 123 )
88
+
89
+ example docstring + " (#{locale})" do
90
+ I18n.locale = locale
91
+ Metar::Wind.new( direction, speed, gusts ).to_s.
92
+ should == expected
93
+ end
94
+ end
95
+
96
+ end
97
+
98
+ end
99
+
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: 45
4
+ hash: 35
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 11
10
- version: 0.9.11
9
+ - 12
10
+ version: 0.9.12
11
11
  platform: ruby
12
12
  authors:
13
13
  - Joe Yates
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-05-11 00:00:00 Z
18
+ date: 2012-05-15 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  prerelease: false
@@ -35,8 +35,22 @@ dependencies:
35
35
  type: :runtime
36
36
  - !ruby/object:Gem::Dependency
37
37
  prerelease: false
38
- name: i18n
38
+ name: rdoc
39
39
  version_requirements: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ requirement: *id002
49
+ type: :runtime
50
+ - !ruby/object:Gem::Dependency
51
+ prerelease: false
52
+ name: i18n
53
+ version_requirements: &id003 !ruby/object:Gem::Requirement
40
54
  none: false
41
55
  requirements:
42
56
  - - ">="
@@ -47,12 +61,12 @@ dependencies:
47
61
  - 3
48
62
  - 5
49
63
  version: 0.3.5
50
- requirement: *id002
64
+ requirement: *id003
51
65
  type: :runtime
52
66
  - !ruby/object:Gem::Dependency
53
67
  prerelease: false
54
68
  name: aasm
55
- version_requirements: &id003 !ruby/object:Gem::Requirement
69
+ version_requirements: &id004 !ruby/object:Gem::Requirement
56
70
  none: false
57
71
  requirements:
58
72
  - - ">="
@@ -63,12 +77,12 @@ dependencies:
63
77
  - 1
64
78
  - 5
65
79
  version: 2.1.5
66
- requirement: *id003
80
+ requirement: *id004
67
81
  type: :runtime
68
82
  - !ruby/object:Gem::Dependency
69
83
  prerelease: false
70
84
  name: m9t
71
- version_requirements: &id004 !ruby/object:Gem::Requirement
85
+ version_requirements: &id005 !ruby/object:Gem::Requirement
72
86
  none: false
73
87
  requirements:
74
88
  - - ~>
@@ -79,8 +93,38 @@ dependencies:
79
93
  - 2
80
94
  - 3
81
95
  version: 0.2.3
82
- requirement: *id004
96
+ requirement: *id005
83
97
  type: :runtime
98
+ - !ruby/object:Gem::Dependency
99
+ prerelease: false
100
+ name: rspec
101
+ version_requirements: &id006 !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ hash: 3
107
+ segments:
108
+ - 2
109
+ - 3
110
+ - 0
111
+ version: 2.3.0
112
+ requirement: *id006
113
+ type: :development
114
+ - !ruby/object:Gem::Dependency
115
+ prerelease: false
116
+ name: rcov
117
+ version_requirements: &id007 !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ hash: 3
123
+ segments:
124
+ - 0
125
+ version: "0"
126
+ requirement: *id007
127
+ type: :development
84
128
  description: A Ruby library which handle METAR weather reports. Provides weather station listings and info. Downloads and parses reports. Presents localized full text reports
85
129
  email: joe.g.yates@gmail.com
86
130
  executables: []
@@ -102,13 +146,22 @@ files:
102
146
  - lib/metar/report.rb
103
147
  - lib/metar/version.rb
104
148
  - lib/metar/raw.rb
105
- - test/metar_test_helper.rb
106
- - test/unit/data_test.rb
107
- - test/unit/parser_test.rb
108
- - test/unit/report_test.rb
109
- - test/unit/station_test.rb
110
- - test/unit/raw_test.rb
111
- - test/all_tests.rb
149
+ - spec/unit/runway_visible_range_spec.rb
150
+ - spec/unit/vertical_visibility_spec.rb
151
+ - spec/unit/report_spec.rb
152
+ - spec/unit/temperature_spec.rb
153
+ - spec/unit/sky_condition_spec.rb
154
+ - spec/unit/visibility_spec.rb
155
+ - spec/unit/weather_phenomenon_spec.rb
156
+ - spec/unit/station_spec.rb
157
+ - spec/unit/parser_spec.rb
158
+ - spec/unit/pressure_spec.rb
159
+ - spec/unit/variable_wind_spec.rb
160
+ - spec/unit/wind_spec.rb
161
+ - spec/unit/raw_spec.rb
162
+ - spec/unit/speed_spec.rb
163
+ - spec/unit/distance_spec.rb
164
+ - spec/spec_helper.rb
112
165
  - locales/it.yml
113
166
  - locales/en.yml
114
167
  homepage: http://github.com/joeyates/metar-parser
@@ -145,4 +198,18 @@ signing_key:
145
198
  specification_version: 3
146
199
  summary: A Ruby library for METAR weather reports
147
200
  test_files:
148
- - test/all_tests.rb
201
+ - spec/unit/runway_visible_range_spec.rb
202
+ - spec/unit/vertical_visibility_spec.rb
203
+ - spec/unit/report_spec.rb
204
+ - spec/unit/temperature_spec.rb
205
+ - spec/unit/sky_condition_spec.rb
206
+ - spec/unit/visibility_spec.rb
207
+ - spec/unit/weather_phenomenon_spec.rb
208
+ - spec/unit/station_spec.rb
209
+ - spec/unit/parser_spec.rb
210
+ - spec/unit/pressure_spec.rb
211
+ - spec/unit/variable_wind_spec.rb
212
+ - spec/unit/wind_spec.rb
213
+ - spec/unit/raw_spec.rb
214
+ - spec/unit/speed_spec.rb
215
+ - spec/unit/distance_spec.rb