dwml 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/.rspec +2 -0
- data/Gemfile +10 -0
- data/LICENSE +21 -0
- data/README.md +4 -0
- data/dwml.gemspec +32 -0
- data/lib/dwml/data_extractor.rb +53 -0
- data/lib/dwml/head_extractor.rb +47 -0
- data/lib/dwml/location.rb +31 -0
- data/lib/dwml/parameter_extractor.rb +279 -0
- data/lib/dwml/time_layout.rb +53 -0
- data/lib/dwml/version.rb +3 -0
- data/lib/dwml.rb +36 -0
- data/spec/lib/dwml/location_spec.rb +24 -0
- data/spec/lib/dwml/parameter_extractor_spec.rb +81 -0
- data/spec/lib/dwml/time_layout_spec.rb +27 -0
- data/spec/spec_helper.rb +19 -0
- metadata +128 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bd148c3dd2ef35a098cdaab6f8dc37e7c35276ee
|
4
|
+
data.tar.gz: c4844f0451e8cba714da7af6837aad3756d713b8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c8f59e69faa76af529e15c2b1722b7e26fdeb4d380dd93d36ebe6fde37419a4ef94cfd92ea32b606f0830741d53a7abb1ec83895a2e631820a37b1bd8fa62213
|
7
|
+
data.tar.gz: 3e17350c0a31ee30197f2c3beef7914043f02b30e6903d6226fce9d06f4f9a0c5b71b51d254f6adf900c6f1841a3e275272e11848870015d71a5f915873d2060
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Angelo Lakra
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
data/dwml.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
lib = File.expand_path('../lib/', __FILE__)
|
2
|
+
$:.unshift lib unless $:.include?(lib)
|
3
|
+
|
4
|
+
require 'dwml/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "dwml"
|
8
|
+
s.version = DWML::VERSION
|
9
|
+
s.platform = Gem::Platform::RUBY
|
10
|
+
s.authors = ["Angelo Lakra"]
|
11
|
+
s.email = ["angelo.lakra@gmail.com"]
|
12
|
+
s.summary = "A parser for NOAA's Digital Weather Markup Language (DWML)"
|
13
|
+
|
14
|
+
s.description = <<-EOT
|
15
|
+
Parses DWML and outputs it into ruby arrays/hashes
|
16
|
+
EOT
|
17
|
+
|
18
|
+
s.homepage = "https://github.com/alakra/dwml"
|
19
|
+
s.licenses = ['MIT']
|
20
|
+
|
21
|
+
s.extra_rdoc_files = ['README.md']
|
22
|
+
|
23
|
+
s.add_runtime_dependency 'nokogiri', '~> 1.6.1', '>= 1.6.1'
|
24
|
+
s.add_runtime_dependency 'multi_json', '~> 1.9.0', '>= 1.9.0'
|
25
|
+
s.add_runtime_dependency 'activesupport', '~> 4.1.0', '>= 4.1.0'
|
26
|
+
|
27
|
+
s.required_ruby_version = '>= 1.9.3'
|
28
|
+
|
29
|
+
s.files = `git ls-files`.split("\n")
|
30
|
+
s.test_files = `git ls-files -- spec/*`.split("\n")
|
31
|
+
s.require_path = 'lib'
|
32
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'dwml/location'
|
2
|
+
require 'dwml/time_layout'
|
3
|
+
require 'dwml/parameter_extractor'
|
4
|
+
|
5
|
+
class DWML
|
6
|
+
class DataExtractor
|
7
|
+
attr_reader :output, :element
|
8
|
+
|
9
|
+
def initialize(element)
|
10
|
+
@element = element
|
11
|
+
@locations = []
|
12
|
+
@time_layouts = []
|
13
|
+
@output = {}
|
14
|
+
end
|
15
|
+
|
16
|
+
def process
|
17
|
+
extract_locations
|
18
|
+
extract_time_layouts
|
19
|
+
extract_parameters
|
20
|
+
|
21
|
+
output
|
22
|
+
end
|
23
|
+
|
24
|
+
protected
|
25
|
+
|
26
|
+
def extract_locations
|
27
|
+
@locations = Location.extract(element.xpath("location"))
|
28
|
+
end
|
29
|
+
|
30
|
+
def extract_time_layouts
|
31
|
+
@time_layouts = TimeLayout.extract(element.xpath("time-layout"))
|
32
|
+
end
|
33
|
+
|
34
|
+
def extract_parameters
|
35
|
+
parameters = element.xpath("parameters")
|
36
|
+
|
37
|
+
@output.merge!(
|
38
|
+
:parameters => parameters.inject({}) do |memo, parameter|
|
39
|
+
location = location_for_parameter(parameter)
|
40
|
+
extractor = ParameterExtractor.new(parameter, location, @time_layouts)
|
41
|
+
memo.merge!(location.location_key => extractor.process)
|
42
|
+
memo
|
43
|
+
end
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
47
|
+
def location_for_parameter(parameter)
|
48
|
+
@locations.detect do |location|
|
49
|
+
parameter.attributes["applicable-location"].text == location.location_key
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
class DWML
|
2
|
+
class HeadExtractor
|
3
|
+
attr_reader :output, :element
|
4
|
+
|
5
|
+
def initialize(element)
|
6
|
+
@element = element
|
7
|
+
@output = {}
|
8
|
+
end
|
9
|
+
|
10
|
+
def process
|
11
|
+
build_product
|
12
|
+
build_source
|
13
|
+
output
|
14
|
+
end
|
15
|
+
|
16
|
+
protected
|
17
|
+
|
18
|
+
def build_product
|
19
|
+
creation_date = Time.zone.parse(element.xpath('product/creation-date').text)
|
20
|
+
|
21
|
+
@output.merge!(
|
22
|
+
:product => {
|
23
|
+
:title => element.xpath('product/title').text,
|
24
|
+
:field => element.xpath('product/field').text,
|
25
|
+
:category => element.xpath('product/category').text,
|
26
|
+
:creation_date => creation_date
|
27
|
+
}
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
def build_source
|
32
|
+
sub_center = element.xpath('source/production-center/sub-center').text
|
33
|
+
production_center = element.xpath('source/production-center').text
|
34
|
+
|
35
|
+
@output.merge!(
|
36
|
+
:source => {
|
37
|
+
:more_information => element.xpath('source/more-information').text,
|
38
|
+
:product_center => production_center.gsub(sub_center, " - #{sub_center}"),
|
39
|
+
:disclaimer => element.xpath('source/disclaimer').text,
|
40
|
+
:credit => element.xpath('source/credit').text,
|
41
|
+
:credit_logo => element.xpath('source/credit-logo').text,
|
42
|
+
:feedback => element.xpath('source/feedback').text
|
43
|
+
}
|
44
|
+
)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class DWML
|
2
|
+
class Location
|
3
|
+
class << self
|
4
|
+
def extract(elements)
|
5
|
+
elements.map { |element| new(element) }
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
attr_reader :element, :location_key, :latitude, :longitude
|
10
|
+
|
11
|
+
def initialize(element)
|
12
|
+
@element = element
|
13
|
+
|
14
|
+
extract_key
|
15
|
+
extract_coords
|
16
|
+
end
|
17
|
+
|
18
|
+
protected
|
19
|
+
|
20
|
+
def extract_key
|
21
|
+
@location_key = element.xpath("location-key").first.text
|
22
|
+
end
|
23
|
+
|
24
|
+
def extract_coords
|
25
|
+
point = element.xpath('point').first
|
26
|
+
|
27
|
+
@latitude = point.attributes["latitude"].text.to_f
|
28
|
+
@longitude = point.attributes["longitude"].text.to_f
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,279 @@
|
|
1
|
+
class DWML
|
2
|
+
class ParameterExtractor
|
3
|
+
attr_reader :output, :element, :location, :time_layouts
|
4
|
+
|
5
|
+
def initialize(element, location, time_layouts)
|
6
|
+
@element = element
|
7
|
+
@location = location
|
8
|
+
@time_layouts = time_layouts
|
9
|
+
|
10
|
+
@output = {
|
11
|
+
:latitude => location.latitude,
|
12
|
+
:longitude => location.longitude
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
def process
|
17
|
+
extract_temperatures
|
18
|
+
extract_precipitation
|
19
|
+
extract_wind_speed
|
20
|
+
extract_wind_direction
|
21
|
+
extract_cloud_cover
|
22
|
+
extract_probability_of_precipitation
|
23
|
+
extract_fire_weather
|
24
|
+
extract_convective_hazard
|
25
|
+
extract_climate_anomaly
|
26
|
+
extract_humidity
|
27
|
+
extract_weather
|
28
|
+
extract_conditions_icons
|
29
|
+
extract_hazards
|
30
|
+
extract_water_state
|
31
|
+
|
32
|
+
output
|
33
|
+
end
|
34
|
+
|
35
|
+
protected
|
36
|
+
|
37
|
+
def extract_temperatures
|
38
|
+
extract_basic_time_series(:temperature)
|
39
|
+
end
|
40
|
+
|
41
|
+
def extract_precipitation
|
42
|
+
extract_basic_time_series(:precipitation)
|
43
|
+
end
|
44
|
+
|
45
|
+
def extract_wind_speed
|
46
|
+
extract_basic_time_series(:"wind-speed")
|
47
|
+
end
|
48
|
+
|
49
|
+
def extract_wind_direction
|
50
|
+
extract_basic_time_series(:direction)
|
51
|
+
end
|
52
|
+
|
53
|
+
def extract_cloud_cover
|
54
|
+
extract_basic_time_series(:"cloud-amount")
|
55
|
+
end
|
56
|
+
|
57
|
+
def extract_probability_of_precipitation
|
58
|
+
extract_basic_time_series(:"probability-of-precipitation")
|
59
|
+
end
|
60
|
+
|
61
|
+
def extract_humidity
|
62
|
+
extract_basic_time_series(:humidity)
|
63
|
+
end
|
64
|
+
|
65
|
+
def extract_fire_weather
|
66
|
+
extract_basic_time_series(:"fire-weather")
|
67
|
+
end
|
68
|
+
|
69
|
+
def extract_water_state
|
70
|
+
node = element.xpath("water-state").first
|
71
|
+
return if node.blank?
|
72
|
+
|
73
|
+
@output[:"water-state"] = {}
|
74
|
+
layout = lookup_time_layout(node)
|
75
|
+
|
76
|
+
waves_node = node.xpath("waves").first
|
77
|
+
@output[:"water-state"][:type] = waves_node.attributes["type"].text
|
78
|
+
@output[:"water-state"][:unit] = waves_node.attributes["units"].text
|
79
|
+
@output[:"water-state"][:values] = []
|
80
|
+
|
81
|
+
waves_node.xpath("value").each_with_index do |value, index|
|
82
|
+
@output[:"water-state"][:values] << {
|
83
|
+
:value => value.text,
|
84
|
+
:start_time => layout.valid_times[index].start
|
85
|
+
}
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def extract_hazards
|
90
|
+
node = element.xpath("hazards").first
|
91
|
+
return if node.blank?
|
92
|
+
|
93
|
+
layout = lookup_time_layout(node)
|
94
|
+
|
95
|
+
@output[:hazards] = {
|
96
|
+
:name => node.xpath("name").first.text,
|
97
|
+
:conditions => node.xpath("hazard-conditions").each_with_index.map do |condition_node, index|
|
98
|
+
hazard_node = condition_node.xpath("hazard").first
|
99
|
+
next if hazard_node.blank?
|
100
|
+
|
101
|
+
{
|
102
|
+
:code => hazard_node.attributes["hazardCode"].text,
|
103
|
+
:phenomena => hazard_node.attributes["phenomena"].text,
|
104
|
+
:significance => hazard_node.attributes["significance"].text,
|
105
|
+
:type => hazard_node.attributes["hazardType"].text,
|
106
|
+
:url => hazard_node.xpath("hazardTextURL").first.text,
|
107
|
+
:start_time => layout.valid_times[index].start
|
108
|
+
}
|
109
|
+
end.compact
|
110
|
+
}
|
111
|
+
end
|
112
|
+
|
113
|
+
def extract_conditions_icons
|
114
|
+
node = element.xpath("conditions-icon").first
|
115
|
+
return if node.blank?
|
116
|
+
|
117
|
+
layout = lookup_time_layout(node)
|
118
|
+
|
119
|
+
@output[:"conditions-icon"] = {
|
120
|
+
:name => node.xpath("name").text,
|
121
|
+
:type => node.attributes["type"].text,
|
122
|
+
:links => node.xpath("icon-link").each_with_index.map do |icon_node, index|
|
123
|
+
{
|
124
|
+
:link => icon_node.text,
|
125
|
+
:start_time => layout.valid_times[index].start
|
126
|
+
}
|
127
|
+
end
|
128
|
+
}
|
129
|
+
end
|
130
|
+
|
131
|
+
def extract_convective_hazard
|
132
|
+
return if element.xpath("convective-hazard").blank?
|
133
|
+
|
134
|
+
@output[:"convective-hazard"] ||= {
|
135
|
+
:outlook => { :name => nil, :values => []},
|
136
|
+
:"severe-component" => []
|
137
|
+
}
|
138
|
+
|
139
|
+
extract_convective_hazard_outlook
|
140
|
+
extract_convective_hazard_severity
|
141
|
+
end
|
142
|
+
|
143
|
+
def extract_convective_hazard_outlook
|
144
|
+
outlook_node = element.xpath("convective-hazard/outlook").first
|
145
|
+
layout = lookup_time_layout(outlook_node)
|
146
|
+
|
147
|
+
@output[:"convective-hazard"][:outlook][:name] = outlook_node.xpath("node").text
|
148
|
+
|
149
|
+
outlook_node.xpath("value").each_with_index do |value, index|
|
150
|
+
@output[:"convective-hazard"][:outlook][:values] << {
|
151
|
+
:start_time => layout.valid_times[index].start,
|
152
|
+
:end_time => layout.valid_times[index].stop,
|
153
|
+
:value => value.text
|
154
|
+
}
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
def extract_convective_hazard_severity
|
159
|
+
element.xpath("convective-hazard/severe-component").each do |node|
|
160
|
+
layout = lookup_time_layout(node)
|
161
|
+
|
162
|
+
hsh = {
|
163
|
+
:name => node.xpath("name").first.text,
|
164
|
+
:type => node.attributes["type"].text,
|
165
|
+
:unit => node.attributes["units"].text,
|
166
|
+
:values => node.xpath("value").each_with_index.map do |value, index|
|
167
|
+
{
|
168
|
+
:value => value.text,
|
169
|
+
:start_time => layout.valid_times[index].start,
|
170
|
+
:end_time => layout.valid_times[index].stop
|
171
|
+
}
|
172
|
+
end
|
173
|
+
}
|
174
|
+
|
175
|
+
@output[:"convective-hazard"][:"severe-component"] << hsh
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
def extract_climate_anomaly
|
180
|
+
return if element.xpath("climate-anomaly").blank?
|
181
|
+
|
182
|
+
[:weekly, :monthly, :seasonal].each do |period|
|
183
|
+
element.xpath("climate-anomaly/#{period.to_s}").each_with_index do |node|
|
184
|
+
layout = lookup_time_layout(node)
|
185
|
+
valid_time = layout.valid_times.first
|
186
|
+
|
187
|
+
@output[:"climate-anomaly"] ||= {}
|
188
|
+
@output[:"climate-anomaly"][period] ||= []
|
189
|
+
@output[:"climate-anomaly"][period] << {
|
190
|
+
:name => node.xpath("name").first.text,
|
191
|
+
:value => node.xpath("value").first.text,
|
192
|
+
:type => node.attributes["type"].text,
|
193
|
+
:unit => node.attributes["units"].text,
|
194
|
+
:start_time => valid_time.start,
|
195
|
+
:end_time => valid_time.stop
|
196
|
+
}
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
def extract_weather
|
202
|
+
node = element.xpath("weather")
|
203
|
+
return if node.blank?
|
204
|
+
|
205
|
+
node.map do |weather_node|
|
206
|
+
@output[:weather] ||= {}
|
207
|
+
@output[:weather][:name] = weather_node.xpath("name").text
|
208
|
+
@output[:weather][:conditions] ||= []
|
209
|
+
|
210
|
+
layout = lookup_time_layout(weather_node)
|
211
|
+
|
212
|
+
weather_node.xpath("weather-conditions").each_with_index do |condition, index|
|
213
|
+
value = condition.xpath("value").first
|
214
|
+
next if value.blank?
|
215
|
+
|
216
|
+
visibility_node = value.xpath("visibility").first
|
217
|
+
visibility = if visibility_node.present? && visibility_node.text.present?
|
218
|
+
{
|
219
|
+
:unit => visibility_node.attributes["units"].text,
|
220
|
+
:value => visibility_node.text.to_f
|
221
|
+
}
|
222
|
+
else
|
223
|
+
""
|
224
|
+
end
|
225
|
+
|
226
|
+
hsh = {
|
227
|
+
:start_time => layout.valid_times[index].start,
|
228
|
+
:coverage => value.attributes["coverage"].text,
|
229
|
+
:intensity => value.attributes["intensity"].text,
|
230
|
+
:"weather-type" => value.attributes["weather-type"].text,
|
231
|
+
:qualifier => value.attributes["qualifier"].text,
|
232
|
+
:visibility => visibility
|
233
|
+
}
|
234
|
+
|
235
|
+
additive = value.attributes["additive"]
|
236
|
+
hsh.merge!(:additive => additive) if additive.present?
|
237
|
+
|
238
|
+
@output[:weather][:conditions] << hsh
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
def extract_basic_time_series(metric)
|
244
|
+
metric_node = element.xpath(metric.to_s)
|
245
|
+
return if metric_node.blank?
|
246
|
+
|
247
|
+
metric_node.map do |node|
|
248
|
+
layout = lookup_time_layout(node)
|
249
|
+
type = node.attributes["type"].text.to_sym
|
250
|
+
unit = node.attributes["units"].try(:text)
|
251
|
+
|
252
|
+
@output[metric] ||= {}
|
253
|
+
@output[metric][type] ||= {}
|
254
|
+
@output[metric][type][:name] = node.xpath("name").text
|
255
|
+
@output[metric][type][:values] = []
|
256
|
+
|
257
|
+
node.xpath("value").each_with_index do |value, index|
|
258
|
+
hsh = {
|
259
|
+
:value => value.text.to_f,
|
260
|
+
:start_time => layout.valid_times[index].start
|
261
|
+
}
|
262
|
+
|
263
|
+
end_time = layout.valid_times[index].stop
|
264
|
+
|
265
|
+
hsh.merge!(:unit => unit) if unit.present?
|
266
|
+
hsh.merge!(:end_time => end_time) if end_time.present?
|
267
|
+
|
268
|
+
@output[metric][type][:values] << hsh
|
269
|
+
end
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
def lookup_time_layout(node)
|
274
|
+
@time_layouts.detect do |layout|
|
275
|
+
node.attributes["time-layout"].text == layout.layout_key
|
276
|
+
end
|
277
|
+
end
|
278
|
+
end
|
279
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
class DWML
|
2
|
+
class TimeLayout
|
3
|
+
class << self
|
4
|
+
def extract(elements)
|
5
|
+
elements.map { |element| new(element) }
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
attr_reader :element, :time_coordinate, :summarization, :layout_key, :valid_times
|
10
|
+
|
11
|
+
def initialize(element)
|
12
|
+
@element = element
|
13
|
+
@valid_times = []
|
14
|
+
|
15
|
+
extract_time_coordinate
|
16
|
+
extract_summarization
|
17
|
+
extract_layout_key
|
18
|
+
extract_valid_times
|
19
|
+
end
|
20
|
+
|
21
|
+
protected
|
22
|
+
|
23
|
+
def extract_time_coordinate
|
24
|
+
@time_coordinate = element.attributes["time-coordinate"].text
|
25
|
+
end
|
26
|
+
|
27
|
+
def extract_summarization
|
28
|
+
@summarization = element.attributes["summarization"].text
|
29
|
+
end
|
30
|
+
|
31
|
+
def extract_layout_key
|
32
|
+
@layout_key = element.xpath("layout-key").first.text
|
33
|
+
end
|
34
|
+
|
35
|
+
def extract_valid_times
|
36
|
+
start_times = element.xpath("start-valid-time")
|
37
|
+
stop_times = element.xpath("end-valid-time")
|
38
|
+
|
39
|
+
start_times.each_with_index do |start_time, index|
|
40
|
+
@valid_times << ValidTime.new(start_time.text, stop_times[index].try(:text))
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class ValidTime
|
45
|
+
attr_reader :start, :stop
|
46
|
+
|
47
|
+
def initialize(start, stop)
|
48
|
+
@start = Time.zone.parse(start.to_s)
|
49
|
+
@stop = Time.zone.parse(stop.to_s)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/dwml/version.rb
ADDED
data/lib/dwml.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'multi_json'
|
2
|
+
|
3
|
+
require 'dwml/head_extractor'
|
4
|
+
require 'dwml/data_extractor'
|
5
|
+
|
6
|
+
#
|
7
|
+
# Note: See http://graphical.weather.gov/xml/mdl/XML/Design/MDL_XML_Design.pdf
|
8
|
+
# for authoritative type definitions
|
9
|
+
################################################################################
|
10
|
+
|
11
|
+
class DWML
|
12
|
+
attr_reader :output, :xmldoc
|
13
|
+
|
14
|
+
def initialize(xmldoc)
|
15
|
+
@xmldoc = xmldoc
|
16
|
+
@output = {}
|
17
|
+
end
|
18
|
+
|
19
|
+
def process
|
20
|
+
build_head
|
21
|
+
build_data
|
22
|
+
output
|
23
|
+
end
|
24
|
+
|
25
|
+
protected
|
26
|
+
|
27
|
+
def build_head
|
28
|
+
extractor = HeadExtractor.new(xmldoc.xpath("//dwml/head").first)
|
29
|
+
@output.merge!(extractor.process)
|
30
|
+
end
|
31
|
+
|
32
|
+
def build_data
|
33
|
+
extractor = DataExtractor.new(xmldoc.xpath("//dwml/data").first)
|
34
|
+
@output.merge!(extractor.process)
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DWML::Location do
|
4
|
+
describe ".extract" do
|
5
|
+
end
|
6
|
+
|
7
|
+
context "after initialization" do
|
8
|
+
describe "#element" do
|
9
|
+
it "returns original element"
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#location_key" do
|
13
|
+
it "returns the location_key"
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#latitude" do
|
17
|
+
it "returns the correct latitude"
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#longitude" do
|
21
|
+
it "returns the correct longitude"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DWML::ParameterExtractor do
|
4
|
+
describe "after initialize" do
|
5
|
+
describe "#element" do
|
6
|
+
it "returns the original XML element"
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "#location" do
|
10
|
+
it "returns the location"
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#time_layouts" do
|
14
|
+
it "returns time layouts"
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#output" do
|
18
|
+
it "returns a pair of lat/longs"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#process" do
|
23
|
+
context "for temperatures" do
|
24
|
+
it "returns valid temperatures with associated timestamps"
|
25
|
+
end
|
26
|
+
|
27
|
+
context "for extracting precipitation" do
|
28
|
+
it "returns valid precipitation with associated timestamps"
|
29
|
+
end
|
30
|
+
|
31
|
+
context "for extracting wind speed" do
|
32
|
+
it "returns valid wind speed with associated timestamps"
|
33
|
+
end
|
34
|
+
|
35
|
+
context "for extracting wind direction" do
|
36
|
+
it "returns valid wind direction with associated timestamps"
|
37
|
+
end
|
38
|
+
|
39
|
+
context "for extracting cloud cover" do
|
40
|
+
it "returns valid cloud cover with associated timestamps"
|
41
|
+
end
|
42
|
+
|
43
|
+
context "for extracting probability of precipitation" do
|
44
|
+
it "returns valid probability of precipitation with associated timestamps"
|
45
|
+
end
|
46
|
+
|
47
|
+
context "for extracting fire weather" do
|
48
|
+
it "returns valid fire weather with associated timestamps"
|
49
|
+
end
|
50
|
+
|
51
|
+
context "for extracting convective hazard" do
|
52
|
+
it "returns valid convective hazard with associated timestamps"
|
53
|
+
end
|
54
|
+
|
55
|
+
context "for extracting climate anomaly" do
|
56
|
+
it "returns valid climate anomaly with associated timestamps"
|
57
|
+
end
|
58
|
+
|
59
|
+
context "for extracting humidity" do
|
60
|
+
it "returns valid humidity with associated timestamps"
|
61
|
+
end
|
62
|
+
|
63
|
+
context "for extracting weather" do
|
64
|
+
it "returns valid weather with associated timestamps"
|
65
|
+
end
|
66
|
+
|
67
|
+
context "for extracting conditions icons" do
|
68
|
+
it "returns valid conditions icons with associated timestamps"
|
69
|
+
end
|
70
|
+
|
71
|
+
context "for extracting hazards" do
|
72
|
+
it "returns valid hazards with associated timestamps"
|
73
|
+
end
|
74
|
+
|
75
|
+
context "for extracting water state" do
|
76
|
+
it "returns valid water state with associated timestamps"
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DWML::TimeLayout do
|
4
|
+
describe ".extract" do
|
5
|
+
it "returns a list of parsed XML elements"
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "#element" do
|
9
|
+
it "returns the original XML element"
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#time_coordinate" do
|
13
|
+
it "returns the extracted time coordinate"
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#summarization" do
|
17
|
+
it "returns the extracted summarization"
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#layout_key" do
|
21
|
+
it "returns the extracted layout_key"
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#valid_times" do
|
25
|
+
it "returns the valid start and stop times as a ValidTime"
|
26
|
+
end
|
27
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'dwml'
|
2
|
+
|
3
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
4
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
5
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
6
|
+
# loaded once.
|
7
|
+
#
|
8
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
9
|
+
RSpec.configure do |config|
|
10
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
11
|
+
config.run_all_when_everything_filtered = true
|
12
|
+
config.filter_run :focus
|
13
|
+
|
14
|
+
# Run specs in random order to surface order dependencies. If you find an
|
15
|
+
# order dependency and want to debug it, you can fix the order by providing
|
16
|
+
# the seed, which is printed after each run.
|
17
|
+
# --seed 1234
|
18
|
+
config.order = 'random'
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dwml
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Angelo Lakra
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.6.1
|
20
|
+
- - '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.6.1
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.6.1
|
30
|
+
- - '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.6.1
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: multi_json
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ~>
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 1.9.0
|
40
|
+
- - '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 1.9.0
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ~>
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 1.9.0
|
50
|
+
- - '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 1.9.0
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: activesupport
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ~>
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 4.1.0
|
60
|
+
- - '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 4.1.0
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 4.1.0
|
70
|
+
- - '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: 4.1.0
|
73
|
+
description: |2
|
74
|
+
Parses DWML and outputs it into ruby arrays/hashes
|
75
|
+
email:
|
76
|
+
- angelo.lakra@gmail.com
|
77
|
+
executables: []
|
78
|
+
extensions: []
|
79
|
+
extra_rdoc_files:
|
80
|
+
- README.md
|
81
|
+
files:
|
82
|
+
- .gitignore
|
83
|
+
- .rspec
|
84
|
+
- Gemfile
|
85
|
+
- LICENSE
|
86
|
+
- README.md
|
87
|
+
- dwml.gemspec
|
88
|
+
- lib/dwml.rb
|
89
|
+
- lib/dwml/data_extractor.rb
|
90
|
+
- lib/dwml/head_extractor.rb
|
91
|
+
- lib/dwml/location.rb
|
92
|
+
- lib/dwml/parameter_extractor.rb
|
93
|
+
- lib/dwml/time_layout.rb
|
94
|
+
- lib/dwml/version.rb
|
95
|
+
- spec/lib/dwml/location_spec.rb
|
96
|
+
- spec/lib/dwml/parameter_extractor_spec.rb
|
97
|
+
- spec/lib/dwml/time_layout_spec.rb
|
98
|
+
- spec/spec_helper.rb
|
99
|
+
homepage: https://github.com/alakra/dwml
|
100
|
+
licenses:
|
101
|
+
- MIT
|
102
|
+
metadata: {}
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: 1.9.3
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
requirements: []
|
118
|
+
rubyforge_project:
|
119
|
+
rubygems_version: 2.0.3
|
120
|
+
signing_key:
|
121
|
+
specification_version: 4
|
122
|
+
summary: A parser for NOAA's Digital Weather Markup Language (DWML)
|
123
|
+
test_files:
|
124
|
+
- spec/lib/dwml/location_spec.rb
|
125
|
+
- spec/lib/dwml/parameter_extractor_spec.rb
|
126
|
+
- spec/lib/dwml/time_layout_spec.rb
|
127
|
+
- spec/spec_helper.rb
|
128
|
+
has_rdoc:
|