metar-parser 0.1.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.
- data/COPYING +20 -0
- data/README.rdoc +40 -0
- data/Rakefile +53 -0
- data/bin/download_raw.rb +57 -0
- data/bin/parse_raw.rb +28 -0
- data/lib/metar/data.rb +374 -0
- data/lib/metar/parser.rb +352 -0
- data/lib/metar/raw.rb +49 -0
- data/lib/metar/report.rb +95 -0
- data/lib/metar/station.rb +176 -0
- data/lib/metar.rb +16 -0
- data/locales/en.yml +111 -0
- data/locales/it.yml +111 -0
- data/test/all_tests.rb +6 -0
- data/test/metar_test_helper.rb +14 -0
- data/test/unit/data_test.rb +183 -0
- data/test/unit/parser_test.rb +101 -0
- data/test/unit/raw_test.rb +28 -0
- data/test/unit/report_test.rb +91 -0
- data/test/unit/station_test.rb +68 -0
- metadata +128 -0
data/locales/en.yml
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
# encoding: utf8
|
2
|
+
en:
|
3
|
+
date:
|
4
|
+
formats:
|
5
|
+
default: '%d/%m/%Y'
|
6
|
+
comparison:
|
7
|
+
more_than: more than
|
8
|
+
less_than: less than
|
9
|
+
units:
|
10
|
+
pressure:
|
11
|
+
bar:
|
12
|
+
full: bar
|
13
|
+
metar:
|
14
|
+
altitude:
|
15
|
+
at: at
|
16
|
+
distance:
|
17
|
+
unknown: unknown
|
18
|
+
sky_conditions:
|
19
|
+
clear skies: clear skies
|
20
|
+
broken: broken cloud
|
21
|
+
few: few clouds
|
22
|
+
scattered: scattered cloud
|
23
|
+
overcast: overcast
|
24
|
+
runway_visible_range:
|
25
|
+
runway: runway
|
26
|
+
from: from
|
27
|
+
to: to
|
28
|
+
weather:
|
29
|
+
mist: mist
|
30
|
+
dust: dust
|
31
|
+
blowing dust: blowing dust
|
32
|
+
low drifting dust: low drifting dust
|
33
|
+
nearby blowing dust: nearby blowing dust
|
34
|
+
heavy drizzle: heavy drizzle
|
35
|
+
light drizzle: light drizzle
|
36
|
+
heavy freezing drizzle: heavy freezing drizzle
|
37
|
+
light freezing drizzle: light freezing drizzle
|
38
|
+
fog: fog
|
39
|
+
patches of fog: patches of fog
|
40
|
+
freezing fog: freezing fog
|
41
|
+
shallow fog: shallow fog
|
42
|
+
partial fog: partial fog
|
43
|
+
nearby fog: nearby fog
|
44
|
+
smoke: smoke
|
45
|
+
hail: hail
|
46
|
+
heavy shower of hail: heavy shower of hail
|
47
|
+
light shower of hail: light shower of hail
|
48
|
+
heavy shower of small hail: heavy shower of small hail
|
49
|
+
light shower of small hail: light shower of small hail
|
50
|
+
haze: haze
|
51
|
+
ice crystals: ice crystals
|
52
|
+
heavy ice pellets: heavy ice pellets
|
53
|
+
light ice pellets: light ice pellets
|
54
|
+
dust whirls: dust whirls
|
55
|
+
nearby dust whirls: nearby dust whirls
|
56
|
+
spray: spray
|
57
|
+
rain: rain
|
58
|
+
heavy rain: heavy rain
|
59
|
+
light rain: light rain
|
60
|
+
heavy shower of rain: heavy shower of rain
|
61
|
+
light shower of rain: light shower of rain
|
62
|
+
heavy freezing rain: heavy freezing rain
|
63
|
+
light freezing rain: light freezing rain
|
64
|
+
sand: sand
|
65
|
+
blowing sand: blowing sand
|
66
|
+
low drifting sand: low drifting sand
|
67
|
+
nearby blowing sand: nearby blowing sand
|
68
|
+
nearby shower: nearby shower
|
69
|
+
snow: snow
|
70
|
+
heavy snow: heavy snow
|
71
|
+
light snow: light snow
|
72
|
+
heavy shower of snow: heavy shower of snow
|
73
|
+
light shower of snow: light shower of snow
|
74
|
+
blowing snow: blowing snow
|
75
|
+
low drifting snow: low drifting snow
|
76
|
+
nearby blowing snow: nearby blowing snow
|
77
|
+
heavy snow grains: heavy snow grains
|
78
|
+
light snow grains: light snow grains
|
79
|
+
snow and rain: snow and rain
|
80
|
+
squall: squall
|
81
|
+
unknown phenomenon: unknown phenomenon
|
82
|
+
heavy freezing unknown phenomenon: heavy freezing unknown phenomenon
|
83
|
+
light freezing unknown phenomenon: light freezing unknown phenomenon
|
84
|
+
heavy shower of freezing unknown phenomenon: heavy shower of freezing unknown phenomenon
|
85
|
+
light shower of freezing unknown phenomenon: light shower of freezing unknown phenomenon
|
86
|
+
volcanic ash: volcanic ash
|
87
|
+
nearby volcanic ash: nearby volcanic ash
|
88
|
+
funnel cloud: funnel cloud
|
89
|
+
nearby funnel cloud: nearby funnel cloud
|
90
|
+
sand storm: sand storm
|
91
|
+
heavy sand storm: heavy sand storm
|
92
|
+
light sand storm: light sand storm
|
93
|
+
nearby sand storm: nearby sand storm
|
94
|
+
dust storm: dust storm
|
95
|
+
heavy dust storm: heavy dust storm
|
96
|
+
light dust storm: light dust storm
|
97
|
+
nearby dust storm: nearby dust storm
|
98
|
+
thunderstorm: thunderstorm
|
99
|
+
nearby thunderstorm: nearby thunderstorm
|
100
|
+
heavy thunderstorm and hail: heavy thunderstorm and hail
|
101
|
+
light thunderstorm and hail: light thunderstorm and hail
|
102
|
+
heavy thunderstorm and small hail: heavy thunderstorm and small hail
|
103
|
+
light thunderstorm and small hail: light thunderstorm and small hail
|
104
|
+
heavy thunderstorm and rain: heavy thunderstorm and rain
|
105
|
+
light thunderstorm and rain: light thunderstorm and rain
|
106
|
+
heavy thunderstorm and snow: heavy thunderstorm and snow
|
107
|
+
light thunderstorm and snow: light thunderstorm and snow
|
108
|
+
heavy thunderstorm and unknown phenomenon: heavy thunderstorm and unknown phenomenon
|
109
|
+
light thunderstorm and unknown phenomenon: light thunderstorm and unknown phenomenon
|
110
|
+
heavy unknown phenomenon: heavy unknown phenomenon
|
111
|
+
light unknown phenomenon: light unknown phenomenon
|
data/locales/it.yml
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
# encoding: utf8
|
2
|
+
it:
|
3
|
+
date:
|
4
|
+
formats:
|
5
|
+
default: '%d/%m/%Y'
|
6
|
+
comparison:
|
7
|
+
more_than: piú di
|
8
|
+
less_than: meno di
|
9
|
+
units:
|
10
|
+
pressure:
|
11
|
+
bar:
|
12
|
+
full: bar
|
13
|
+
metar:
|
14
|
+
altitude:
|
15
|
+
at: a
|
16
|
+
distance:
|
17
|
+
unknown: sconosciuto
|
18
|
+
sky_conditions:
|
19
|
+
clear skies: cielo sereno
|
20
|
+
broken: nuvolosità parziale
|
21
|
+
few: poche nuvole
|
22
|
+
scattered: nuvole sparse
|
23
|
+
overcast: chiuso
|
24
|
+
runway_visible_range:
|
25
|
+
runway: pista
|
26
|
+
from: da
|
27
|
+
to: a
|
28
|
+
weather:
|
29
|
+
mist: foschia
|
30
|
+
dust: polvere
|
31
|
+
blowing dust: polviscolo
|
32
|
+
low drifting dust: deriva bassa di polviscolo # ?
|
33
|
+
nearby blowing dust: deriva vicina di polviscolo # ?
|
34
|
+
heavy drizzle: pioggerellina fitta
|
35
|
+
light drizzle: pioggerellina rada
|
36
|
+
heavy freezing drizzle: pioggerellina ghiacciata pesante
|
37
|
+
light freezing drizzle: pioggerellina ghiacciata leggera
|
38
|
+
fog: nebbia
|
39
|
+
patches of fog: nebbia a banchi
|
40
|
+
freezing fog: nebbia ghiacciata
|
41
|
+
shallow fog: nebbia bassa
|
42
|
+
partial fog: nebbia parziale
|
43
|
+
nearby fog: nebbia vicina
|
44
|
+
smoke: fumo
|
45
|
+
hail: grandine
|
46
|
+
heavy shower of hail: grandinata intensa
|
47
|
+
light shower of hail: grandinata leggera
|
48
|
+
heavy shower of small hail: grandinata fine intensa
|
49
|
+
light shower of small hail: grandinata fine leggera
|
50
|
+
haze: foschia
|
51
|
+
ice crystals: cristalli di ghiaccio
|
52
|
+
heavy ice pellets: caduta intensa di cristalli di ghiaccio
|
53
|
+
light ice pellets: caduta leggera di cristalli di ghiaccio
|
54
|
+
dust whirls: vortici di polvere
|
55
|
+
nearby dust whirls: vortici di polvere vicini
|
56
|
+
spray: "spruzzi d'aqua"
|
57
|
+
rain: pioggia
|
58
|
+
heavy rain: pioggia pesante
|
59
|
+
light rain: pioggia leggera
|
60
|
+
heavy shower of rain: acquazzone intenso
|
61
|
+
light shower of rain: acquazzone leggero
|
62
|
+
heavy freezing rain: pioggia ghiacciata pesante
|
63
|
+
light freezing rain: pioggia ghiacciata leggera
|
64
|
+
sand: sabbia
|
65
|
+
blowing sand: sabbia e vento
|
66
|
+
low drifting sand: deriva bassa di sabbia
|
67
|
+
nearby blowing sand: deriva di sabbia vicina
|
68
|
+
nearby shower: acquazzone vicino
|
69
|
+
snow: neve
|
70
|
+
heavy snow: neve pesante
|
71
|
+
light snow: neve leggera
|
72
|
+
heavy shower of snow: nevicata pesante
|
73
|
+
light shower of snow: nevicata leggera
|
74
|
+
blowing snow: neve portata dal vento
|
75
|
+
low drifting snow: deriva di neve
|
76
|
+
nearby blowing snow: neve portata dal vento vicino
|
77
|
+
heavy snow grains: caudta intensa di granelli di neve
|
78
|
+
light snow grains: caduta leggera di granelli di neve
|
79
|
+
snow and rain: neve mista a pioggia
|
80
|
+
squall: bufera
|
81
|
+
unknown phenomenon: fenomeno sconosciuto
|
82
|
+
heavy freezing unknown phenomenon: fenomeno ghiacciato sconosciuto pesante
|
83
|
+
light freezing unknown phenomenon: fenomeno ghiacciato sconosciuto leggero
|
84
|
+
heavy shower of freezing unknown phenomenon: scroscio pesante ghiacciata di fenomeno sconosciuto
|
85
|
+
light shower of freezing unknown phenomenon: scroscio leggero ghiacciata di fenomeno sconosciuto
|
86
|
+
volcanic ash: cenere volcanica
|
87
|
+
nearby volcanic ash: cenere volcanica vicina
|
88
|
+
funnel cloud: nube a imbuto
|
89
|
+
nearby funnel cloud: nube a imbuto vicina
|
90
|
+
sand storm: tempesta di sabbia
|
91
|
+
heavy sand storm: tempesta di sabbia pesante
|
92
|
+
light sand storm: tempesta di sabbia leggera
|
93
|
+
nearby sand storm: tempesta di sabbia vicina
|
94
|
+
dust storm: tempesta di polvere
|
95
|
+
heavy dust storm: tempesta di polvere pesante
|
96
|
+
light dust storm: tempesta di polvere leggera
|
97
|
+
nearby dust storm: tempesta di polvere vicina
|
98
|
+
thunderstorm: temporale
|
99
|
+
nearby thunderstorm: temporale vicino
|
100
|
+
heavy thunderstorm and hail: temporale con grandine intenso
|
101
|
+
light thunderstorm and hail: temporale con grandine leggero
|
102
|
+
heavy thunderstorm and small hail: temporale con grandine fine intenso
|
103
|
+
light thunderstorm and small hail: temporale con grandine fine leggero
|
104
|
+
heavy thunderstorm and rain: temporale con pioggia intensa
|
105
|
+
light thunderstorm and rain: temporale con pioggia leggera
|
106
|
+
heavy thunderstorm and snow: temporale con neve intensa
|
107
|
+
light thunderstorm and snow: temporale con neve leggera
|
108
|
+
heavy thunderstorm and unknown phenomenon: temporale con fenomeno sconosciuto intenso
|
109
|
+
light thunderstorm and unknown phenomenon: temporale con fenomeno sconosciuto leggero
|
110
|
+
heavy unknown phenomenon: fenomeno sconosciuto intenso
|
111
|
+
light unknown phenomenon: fenomeno sconosciuto leggero
|
data/test/all_tests.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rubygems' if RUBY_VERSION < '1.9'
|
2
|
+
require File.join(File.expand_path(File.dirname(__FILE__) + '/../lib'), 'metar')
|
3
|
+
|
4
|
+
Metar::Station.load_local
|
5
|
+
|
6
|
+
RAW_EXAMPLE = "2010/02/06 15:20\nLIRQ 061520Z 01007KT 350V050 9999 SCT035 BKN080 08/02 Q1005"
|
7
|
+
# Use a fixed string for testing
|
8
|
+
Metar::Raw.instance_eval do
|
9
|
+
def fetch(cccc)
|
10
|
+
RAW_EXAMPLE
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
require 'test/unit'
|
@@ -0,0 +1,183 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
require File.dirname(__FILE__) + '/../metar_test_helper'
|
5
|
+
|
6
|
+
class TestMetarData < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def setup
|
9
|
+
I18n.locale = :en
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_m9t_translations_available
|
13
|
+
assert_equal('10 kilometers', M9t::Distance.new(10000, {:units => :kilometers, :precision => 0}).to_s)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Speed
|
17
|
+
def test_speed_parse_blank_gives_nil
|
18
|
+
speed = Metar::Speed.parse('')
|
19
|
+
assert_nil(speed)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_class_options_set
|
23
|
+
assert_not_nil(Metar::Speed.options)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_speed_parse_default_unit
|
27
|
+
speed = Metar::Speed.parse('12')
|
28
|
+
assert_equal(12, speed.to_kilometers_per_hour)
|
29
|
+
assert_equal(:kilometers_per_hour, speed.options[:units])
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_speed_parse_kilometers_per_hour
|
33
|
+
speed = Metar::Speed.parse('12KMH')
|
34
|
+
assert_equal(12, speed.to_kilometers_per_hour)
|
35
|
+
assert_equal(:kilometers_per_hour, speed.options[:units])
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_speed_parse_knots
|
39
|
+
speed = Metar::Speed.parse('12KT')
|
40
|
+
assert_equal(:knots, speed.options[:units])
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_speed_parse_meters_per_second
|
44
|
+
speed = Metar::Speed.parse('12MPS')
|
45
|
+
assert_equal(:meters_per_second, speed.options[:units])
|
46
|
+
end
|
47
|
+
|
48
|
+
# Temperature
|
49
|
+
def test_temperature_parse_blank_gives_nil
|
50
|
+
temperature = Metar::Temperature.parse('')
|
51
|
+
assert_nil(temperature)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_temperature_parse_incorrect_gives_nil
|
55
|
+
temperature = Metar::Temperature.parse('XYZ')
|
56
|
+
assert_nil(temperature)
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_temperature_parse_positive
|
60
|
+
temperature = Metar::Temperature.parse('12')
|
61
|
+
assert_equal(12, temperature.value)
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_temperature_parse_negative
|
65
|
+
temperature = Metar::Temperature.parse('M12')
|
66
|
+
assert_equal(-12, temperature.value)
|
67
|
+
end
|
68
|
+
|
69
|
+
# Distance
|
70
|
+
def test_distance_nil
|
71
|
+
distance = Metar::Distance.new
|
72
|
+
I18n.locale = :en
|
73
|
+
assert_equal('unknown', distance.to_s)
|
74
|
+
I18n.locale = :it
|
75
|
+
assert_equal('sconosciuto', distance.to_s)
|
76
|
+
end
|
77
|
+
|
78
|
+
# Wind
|
79
|
+
def test_wind
|
80
|
+
wind = Metar::Wind.parse('24006KT')
|
81
|
+
assert_equal(240, wind.direction.value)
|
82
|
+
assert_equal(6, wind.speed.to_knots)
|
83
|
+
assert_equal(:knots, wind.speed.options[:units])
|
84
|
+
end
|
85
|
+
|
86
|
+
# VariableWind
|
87
|
+
def test_variable_wind
|
88
|
+
variable_wind = Metar::VariableWind.parse('350V050')
|
89
|
+
assert_equal(350, variable_wind.direction1.value)
|
90
|
+
assert_equal(50, variable_wind.direction2.value)
|
91
|
+
end
|
92
|
+
|
93
|
+
# Visibility
|
94
|
+
def test_visibility_parse_blank
|
95
|
+
visibility = Metar::Visibility.parse('')
|
96
|
+
assert_nil(visibility)
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_visibility_parse_comparator_defaults_to_nil
|
100
|
+
visibility = Metar::Visibility.parse('0200NDV')
|
101
|
+
assert_nil(visibility.comparator)
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_visibility_parse_9999
|
105
|
+
visibility = Metar::Visibility.parse('9999')
|
106
|
+
assert_equal('more than 10km', visibility.to_s)
|
107
|
+
I18n.locale = :it
|
108
|
+
assert_equal('piú di 10km', visibility.to_s)
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_visibility_parse_ndv
|
112
|
+
visibility = Metar::Visibility.parse('0200NDV')
|
113
|
+
assert_equal(200, visibility.distance.value)
|
114
|
+
assert_nil(visibility.direction)
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_visibility_parse_us_fractions_1_4
|
118
|
+
visibility = Metar::Visibility.parse('1/4SM')
|
119
|
+
assert_equal(M9t::Distance.miles(0.25).value, visibility.distance.value)
|
120
|
+
assert_equal(:miles, visibility.distance.options[:units])
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_visibility_parse_us_fractions_2_1_2
|
124
|
+
visibility = Metar::Visibility.parse('2 1/2SM')
|
125
|
+
assert_equal(M9t::Distance.miles(2.5).value, visibility.distance.value)
|
126
|
+
assert_equal(:miles, visibility.distance.options[:units])
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_visibility_parse_kilometers
|
130
|
+
visibility = Metar::Visibility.parse('5KM')
|
131
|
+
assert_equal(5000.0, visibility.distance.value)
|
132
|
+
assert_equal(:kilometers, visibility.distance.options[:units])
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_visibility_parse_compass
|
136
|
+
visibility = Metar::Visibility.parse('5NE')
|
137
|
+
assert_equal(5000.0, visibility.distance.value)
|
138
|
+
assert_equal(:kilometers, visibility.distance.options[:units])
|
139
|
+
assert_equal(45.0, visibility.direction.value)
|
140
|
+
visibility.distance.options[:units] = :kilometers
|
141
|
+
visibility.distance.options[:abbreviated] = true
|
142
|
+
visibility.distance.options[:precision] = 0
|
143
|
+
visibility.direction.options[:units] = :compass
|
144
|
+
assert_equal('5km NE', visibility.to_s)
|
145
|
+
end
|
146
|
+
|
147
|
+
# RunwayVisibleRange
|
148
|
+
def test_runway_visible_range
|
149
|
+
runway_visible_range = Metar::RunwayVisibleRange.parse('R12/1000N')
|
150
|
+
assert_equal('12', runway_visible_range.designator)
|
151
|
+
assert_equal(1000, runway_visible_range.visibility1.distance.value)
|
152
|
+
assert_equal(:no_change, runway_visible_range.tendency)
|
153
|
+
end
|
154
|
+
|
155
|
+
def test_runway_visible_range_variable
|
156
|
+
runway_visible_range = Metar::RunwayVisibleRange.parse('R10R/1600VP6000FT')
|
157
|
+
assert_equal('10R', runway_visible_range.designator)
|
158
|
+
assert_equal(1600, runway_visible_range.visibility1.distance.to_feet)
|
159
|
+
assert_equal(6000, runway_visible_range.visibility2.distance.to_feet)
|
160
|
+
end
|
161
|
+
|
162
|
+
# WeatherPhenomenon
|
163
|
+
def test_weather_phenomenon_i18n
|
164
|
+
freezing_rain = Metar::WeatherPhenomenon.parse('FZFG')
|
165
|
+
assert_equal('freezing fog', freezing_rain.to_s)
|
166
|
+
I18n.locale = :it
|
167
|
+
assert_equal('nebbia ghiacciata', freezing_rain.to_s)
|
168
|
+
end
|
169
|
+
|
170
|
+
# SkyCondition
|
171
|
+
def test_sky_condition
|
172
|
+
sky_condition = Metar::SkyCondition.parse('BKN016')
|
173
|
+
assert_equal('broken', sky_condition.quantity)
|
174
|
+
assert_equal(480, sky_condition.height.value)
|
175
|
+
end
|
176
|
+
|
177
|
+
# VerticalVisibility
|
178
|
+
def test_vertical_visibility
|
179
|
+
vertical_visibility = Metar::VerticalVisibility.parse('VV001')
|
180
|
+
assert_equal(30, vertical_visibility.value)
|
181
|
+
end
|
182
|
+
|
183
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
require File.dirname(__FILE__) + '/../metar_test_helper'
|
5
|
+
|
6
|
+
class TestMetarParser < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def setup
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_new
|
12
|
+
raw = Metar::Raw.new('PAIL', "2010/02/06 16:10\nPAIL 061610Z 24006KT 1 3/4SM -SN BKN016 OVC030 M17/M20 A2910 RMK AO2 P0000")
|
13
|
+
assert_nothing_thrown do
|
14
|
+
report = Metar::Parser.new(raw)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_date
|
19
|
+
parser = setup_parser('PAIL', "2010/02/06 16:10\nPAIL 061610Z 24006KT 1 3/4SM -SN BKN016 OVC030 M17/M20 A2910 RMK AO2 P0000")
|
20
|
+
assert_equal(Date.new(2010, 2, 6), parser.date)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_wind
|
24
|
+
parser = setup_parser('PAIL', "2010/02/06 16:10\nPAIL 061610Z 24006KT 1 3/4SM -SN BKN016 OVC030 M17/M20 A2910 RMK AO2 P0000")
|
25
|
+
assert_in_delta(240, parser.wind.direction.value, 0.0001)
|
26
|
+
assert_in_delta(6, parser.wind.speed.to_knots, 0.0001)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_variable_wind
|
30
|
+
parser = setup_parser('LIRQ', "2010/02/06 15:20\nLIRQ 061520Z 01007KT 350V050 9999 SCT035 BKN080 08/02 Q1005")
|
31
|
+
assert_in_delta(350, parser.variable_wind.direction1.value, 0.0001)
|
32
|
+
assert_in_delta(50, parser.variable_wind.direction2.value, 0.0001)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_visibility_miles_and_fractions
|
36
|
+
parser = setup_parser('PAIL', "2010/02/06 16:10\nPAIL 061610Z 24006KT 1 3/4SM -SN BKN016 OVC030 M17/M20 A2910 RMK AO2 P0000")
|
37
|
+
assert_in_delta(1.75, parser.visibility.distance.to_miles, 0.01)
|
38
|
+
assert_equal(:miles, parser.visibility.distance.options[:units])
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_runway_visible_range
|
42
|
+
parser = setup_parser('ESSB', "2010/02/15 10:20\nESSB 151020Z 26003KT 2000 R12/1000N R30/1500N VV002 M07/M07 Q1013 1271//55")
|
43
|
+
assert_equal(2, parser.runway_visible_range.length)
|
44
|
+
assert_equal('12', parser.runway_visible_range[0].designator)
|
45
|
+
assert_equal(1000, parser.runway_visible_range[0].visibility1.distance.value)
|
46
|
+
assert_equal(:no_change, parser.runway_visible_range[0].tendency)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_runway_visible_range_variable
|
50
|
+
parser = setup_parser('KPDX', "2010/02/15 11:08\nKPDX 151108Z 11006KT 1/4SM R10R/1600VP6000FT FG OVC002 05/05 A3022 RMK AO2")
|
51
|
+
assert_equal(1600.0, parser.runway_visible_range[0].visibility1.distance.to_feet)
|
52
|
+
assert_equal(:feet, parser.runway_visible_range[0].visibility1.distance.options[:units])
|
53
|
+
assert_equal(6000.0, parser.runway_visible_range[0].visibility2.distance.to_feet)
|
54
|
+
assert_equal(:feet, parser.runway_visible_range[0].visibility2.distance.options[:units])
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_present_weather
|
58
|
+
parser = setup_parser('PAIL', "2010/02/06 16:10\nPAIL 061610Z 24006KT 1 3/4SM -SN BKN016 OVC030 M17/M20 A2910 RMK AO2 P0000")
|
59
|
+
assert_equal(1, parser.present_weather.length)
|
60
|
+
assert_equal('light', parser.present_weather[0].modifier)
|
61
|
+
assert_equal('snow', parser.present_weather[0].phenomenon)
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_sky_conditions
|
65
|
+
parser = setup_parser('PAIL', "2010/02/06 16:10\nPAIL 061610Z 24006KT 1 3/4SM -SN BKN016 OVC030 M17/M20 A2910 RMK AO2 P0000")
|
66
|
+
assert_equal(2, parser.sky_conditions.length)
|
67
|
+
assert_equal('broken', parser.sky_conditions[0].quantity)
|
68
|
+
assert_equal(480, parser.sky_conditions[0].height.value)
|
69
|
+
assert_equal('overcast', parser.sky_conditions[1].quantity)
|
70
|
+
assert_equal(900, parser.sky_conditions[1].height.value)
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_vertical_visibility
|
74
|
+
parser = setup_parser('CYXS', "2010/02/15 10:34\nCYXS 151034Z AUTO 09003KT 1/8SM FZFG VV001 M03/M03 A3019 RMK SLP263 ICG")
|
75
|
+
assert_equal(30, parser.vertical_visibility.value)
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_temperature
|
79
|
+
parser = setup_parser('PAIL', "2010/02/06 16:10\nPAIL 061610Z 24006KT 1 3/4SM -SN BKN016 OVC030 M17/M20 A2910 RMK AO2 P0000")
|
80
|
+
assert_equal(-17, parser.temperature.value)
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_dew_point
|
84
|
+
parser = setup_parser('PAIL', "2010/02/06 16:10\nPAIL 061610Z 24006KT 1 3/4SM -SN BKN016 OVC030 M17/M20 A2910 RMK AO2 P0000")
|
85
|
+
assert_equal(-20, parser.dew_point.value)
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_sea_level_pressure
|
89
|
+
parser = setup_parser('PAIL', "2010/02/06 16:10\nPAIL 061610Z 24006KT 1 3/4SM -SN BKN016 OVC030 M17/M20 A2910 RMK AO2 P0000")
|
90
|
+
assert_equal(29.10, parser.sea_level_pressure.to_inches_of_mercury)
|
91
|
+
assert_equal(:bar, parser.sea_level_pressure.options[:units])
|
92
|
+
end
|
93
|
+
|
94
|
+
private
|
95
|
+
|
96
|
+
def setup_parser(cccc, metar)
|
97
|
+
raw = Metar::Raw.new(cccc, metar)
|
98
|
+
Metar::Parser.new(raw)
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../metar_test_helper'
|
4
|
+
|
5
|
+
class TestMetarRaw < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def setup
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_fetch
|
11
|
+
raw = Metar::Raw.fetch('LIRQ')
|
12
|
+
assert_instance_of(String, raw)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_new
|
16
|
+
assert_nothing_thrown do
|
17
|
+
raw = Metar::Raw.new('LIRQ')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_attributes
|
22
|
+
raw = Metar::Raw.new('LIRQ')
|
23
|
+
assert_equal('LIRQ', raw.cccc)
|
24
|
+
assert_instance_of(Time, raw.time)
|
25
|
+
assert_instance_of(String, raw.metar)
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
require File.dirname(__FILE__) + '/../metar_test_helper'
|
5
|
+
|
6
|
+
class TestMetarReport < Test::Unit::TestCase
|
7
|
+
def setup
|
8
|
+
I18n.locale = :en
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_date
|
12
|
+
report = setup_report('LIRQ', "2010/02/06 15:20\nLIRQ 061520Z 01007KT 350V050 9999 SCT035 BKN080 08/02 Q1005")
|
13
|
+
assert_equal('06/02/2010', report.date)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_time
|
17
|
+
report = setup_report('LIRQ', "2010/02/06 15:20\nLIRQ 061520Z 01007KT 350V050 9999 SCT035 BKN080 08/02 Q1005")
|
18
|
+
assert_equal('15:20', report.time)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_wind_knots
|
22
|
+
report = setup_report('LIRQ', "2010/02/06 15:20\nLIRQ 061520Z 01007KT 350V050 9999 SCT035 BKN080 08/02 Q1005")
|
23
|
+
assert_equal('10° 7 knots', report.wind)
|
24
|
+
I18n.locale = :it
|
25
|
+
assert_equal('10° 7 nodi', report.wind)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_variable_wind
|
29
|
+
report = setup_report('LIRQ', "2010/02/06 15:20\nLIRQ 061520Z 01007KT 350V050 9999 SCT035 BKN080 08/02 Q1005")
|
30
|
+
assert_equal('350 degrees - 50 degrees', report.variable_wind)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_visibility
|
34
|
+
report = setup_report('LIRQ', "2010/02/06 15:20\nLIRQ 061520Z 01007KT 350V050 9999 SCT035 BKN080 08/02 Q1005")
|
35
|
+
assert_equal('more than 10km', report.visibility)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_runway_visible_range
|
39
|
+
report = setup_report('ESSB', "2010/02/15 10:20\nESSB 151020Z 26003KT 2000 R12/1000N R30/1500N VV002 M07/M07 Q1013 1271//55")
|
40
|
+
assert_equal('runway 12: 1000m, runway 30: 1500m', report.runway_visible_range)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_runway_visible_range_variable
|
44
|
+
report = setup_report('KPDX', "2010/02/15 11:08\nKPDX 151108Z 11006KT 1/4SM R10R/1600VP6000FT FG OVC002 05/05 A3022 RMK AO2")
|
45
|
+
assert_equal('runway 10R: from 1600ft to more than 6000ft', report.runway_visible_range)
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_present_weather
|
49
|
+
report = setup_report('DAAS', "2010/02/15 10:00\nDAAS 151000Z 16012KT 9999 -RA FEW010 BKN026 06/05 Q1006")
|
50
|
+
assert_equal('light rain', report.present_weather)
|
51
|
+
I18n.locale = :it
|
52
|
+
assert_equal('pioggia leggera', report.present_weather)
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_sky_conditions
|
56
|
+
report = setup_report('LIRQ', "2010/02/06 15:20\nLIRQ 061520Z 01007KT 350V050 9999 SCT035 BKN080 08/02 Q1005")
|
57
|
+
I18n.locale = :en
|
58
|
+
assert_equal('scattered cloud at 1050m, broken cloud at 2400m', report.sky_conditions)
|
59
|
+
I18n.locale = :it
|
60
|
+
assert_equal('nuvole sparse a 1050m, nuvolosità parziale a 2400m', report.sky_conditions)
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_vertical_visibility
|
64
|
+
report = setup_report('CYXS', "2010/02/15 10:34\nCYXS 151034Z AUTO 09003KT 1/8SM FZFG VV001 M03/M03 A3019 RMK SLP263 ICG")
|
65
|
+
assert_equal('30m', report.vertical_visibility)
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_temperature
|
69
|
+
report = setup_report('LIRQ', "2010/02/06 15:20\nLIRQ 061520Z 01007KT 350V050 9999 SCT035 BKN080 08/02 Q1005")
|
70
|
+
assert_equal('8°C', report.temperature)
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_dew_point
|
74
|
+
report = setup_report('LIRQ', "2010/02/06 15:20\nLIRQ 061520Z 01007KT 350V050 9999 SCT035 BKN080 08/02 Q1005")
|
75
|
+
assert_equal('2°C', report.dew_point)
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_sea_level_pressure
|
79
|
+
report = setup_report('LIRQ', "2010/02/06 15:20\nLIRQ 061520Z 01007KT 350V050 9999 SCT035 BKN080 08/02 Q1005")
|
80
|
+
assert_equal('1.00500 bar', report.sea_level_pressure)
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def setup_report(cccc, metar)
|
86
|
+
raw = Metar::Raw.new(cccc, metar)
|
87
|
+
parser = Metar::Parser.new(raw)
|
88
|
+
Metar::Report.new(parser)
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|