eeml 0.0.4 → 0.0.5
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/Manifest +1 -1
- data/eeml.gemspec +3 -3
- data/lib/eeml/libxml_eeml_parser_v005.rb +25 -28
- data/lib/eeml.rb +1 -1
- data/test/data/complete_namespaced.xml +29 -0
- data/test/test_environment.rb +8 -0
- data.tar.gz.sig +0 -0
- metadata +4 -3
- metadata.gz.sig +0 -0
data/Manifest
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
example.rb
|
2
|
-
eeml.gemspec
|
3
2
|
LICENSE
|
4
3
|
CHANGELOG
|
5
4
|
README
|
@@ -12,6 +11,7 @@ test/data/minimal.xml
|
|
12
11
|
test/data/doc_2_expected.json
|
13
12
|
test/data/list.xml
|
14
13
|
test/data/out_empty.xml
|
14
|
+
test/data/complete_namespaced.xml
|
15
15
|
test/data/no_namespace.xml
|
16
16
|
test/data/doc_1.xml
|
17
17
|
test/data/doc_1.json
|
data/eeml.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{eeml}
|
5
|
-
s.version = "0.0.
|
5
|
+
s.version = "0.0.5"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Neill Bogie, Sam Mulube"]
|
9
9
|
s.cert_chain = ["/home/sam/.gem/gem-public_cert.pem"]
|
10
|
-
s.date = %q{2009-07-
|
10
|
+
s.date = %q{2009-07-08}
|
11
11
|
s.description = %q{Simple little library for programmatically manipulating EEML documents, in particular this library is designed to work with the Pachube web service.}
|
12
12
|
s.email = %q{sam.mulube@gmail.com}
|
13
13
|
s.extra_rdoc_files = ["LICENSE", "CHANGELOG", "README", "lib/eeml.rb", "lib/eeml/constants.rb", "lib/eeml/json_environment_parser_v005.rb", "lib/eeml/output_registry.rb", "lib/eeml/parser_registry.rb", "lib/eeml/libxml_eeml_output_v005.rb", "lib/eeml/libxml_eeml_parser_v005.rb", "lib/eeml/exceptions.rb", "lib/eeml/csv_parser.rb", "lib/eeml/json_output.rb", "lib/eeml/environment.rb", "lib/blank.rb"]
|
14
|
-
s.files = ["example.rb", "
|
14
|
+
s.files = ["example.rb", "LICENSE", "CHANGELOG", "README", "test/test_environment.rb", "test/test_libxml_test_helper.rb", "test/libxml_test_helper.rb", "test/test_libxml_eeml_parser_v005.rb", "test/test_helper.rb", "test/data/minimal.xml", "test/data/doc_2_expected.json", "test/data/list.xml", "test/data/out_empty.xml", "test/data/complete_namespaced.xml", "test/data/no_namespace.xml", "test/data/doc_1.xml", "test/data/doc_1.json", "test/data/doc_2.xml", "lib/eeml.rb", "lib/eeml/constants.rb", "lib/eeml/json_environment_parser_v005.rb", "lib/eeml/output_registry.rb", "lib/eeml/parser_registry.rb", "lib/eeml/libxml_eeml_output_v005.rb", "lib/eeml/libxml_eeml_parser_v005.rb", "lib/eeml/exceptions.rb", "lib/eeml/csv_parser.rb", "lib/eeml/json_output.rb", "lib/eeml/environment.rb", "lib/blank.rb", "schemas/eeml/005.xsd", "Rakefile", "Manifest", "eeml.gemspec"]
|
15
15
|
s.homepage = %q{}
|
16
16
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Eeml", "--main", "README"]
|
17
17
|
s.require_paths = ["lib"]
|
@@ -18,10 +18,9 @@ module Eeml
|
|
18
18
|
end
|
19
19
|
|
20
20
|
#take an xml string containing zero or more environment nodes, and create an array of Environment objects from it.
|
21
|
-
def make_environments_from_xml(xml_str
|
21
|
+
def make_environments_from_xml(xml_str)
|
22
22
|
doc = parse_xml(xml_str)
|
23
23
|
raise MissingNamespace if doc.root.namespaces.namespace.blank?
|
24
|
-
env = Environment.new
|
25
24
|
return extract_environments_from_doc(doc)
|
26
25
|
end
|
27
26
|
|
@@ -54,15 +53,13 @@ module Eeml
|
|
54
53
|
|
55
54
|
#multiple (zero or more)
|
56
55
|
def extract_environments_from_doc(doc)
|
57
|
-
|
58
|
-
env_nodes = doc.find('x:environment')
|
56
|
+
env_nodes = doc.find('x:environment', "x:#{EEML_HREF}")
|
59
57
|
return env_nodes.map{|env_node| new_env = Environment.new; extract_environment_from_node(env_node, new_env)}
|
60
58
|
end
|
61
59
|
|
62
60
|
#single, mandatory
|
63
61
|
def extract_environment_from_doc(doc, env_to_populate)
|
64
|
-
|
65
|
-
env_node = find_first_node_or_fail(doc, 'x:environment', 'environment')
|
62
|
+
env_node = find_first_node_or_fail(doc, 'x:environment', 'environment', "x:#{EEML_HREF}")
|
66
63
|
return extract_environment_from_node(env_node, env_to_populate)
|
67
64
|
end
|
68
65
|
|
@@ -75,19 +72,19 @@ module Eeml
|
|
75
72
|
|
76
73
|
env.creator = env_node['creator']
|
77
74
|
|
78
|
-
env.title = optional_content(env_node, 'x:title', 'title')
|
79
|
-
env.feed_url = optional_content(env_node, 'x:feed', 'feed')
|
80
|
-
env.description = optional_content(env_node, 'x:description', 'description')
|
81
|
-
env.website = optional_content(env_node, 'x:website', 'website')
|
82
|
-
env.status = optional_content(env_node, 'x:status', 'status')
|
83
|
-
env.email = optional_content(env_node, 'x:email', 'email')
|
84
|
-
env.icon = optional_content(env_node, 'x:icon', 'icon')
|
75
|
+
env.title = optional_content(env_node, 'x:title', 'title', "x:#{EEML_HREF}")
|
76
|
+
env.feed_url = optional_content(env_node, 'x:feed', 'feed', "x:#{EEML_HREF}")
|
77
|
+
env.description = optional_content(env_node, 'x:description', 'description', "x:#{EEML_HREF}")
|
78
|
+
env.website = optional_content(env_node, 'x:website', 'website', "x:#{EEML_HREF}")
|
79
|
+
env.status = optional_content(env_node, 'x:status', 'status', "x:#{EEML_HREF}")
|
80
|
+
env.email = optional_content(env_node, 'x:email', 'email', "x:#{EEML_HREF}")
|
81
|
+
env.icon = optional_content(env_node, 'x:icon', 'icon', "x:#{EEML_HREF}")
|
85
82
|
|
86
83
|
#find_first_node_or_fail(env_node, 'x:location', 'location')
|
87
|
-
loc_node = env_node.find_first('x:location')
|
84
|
+
loc_node = env_node.find_first('x:location', "x:#{EEML_HREF}")
|
88
85
|
env.location = extractLocation(loc_node) if loc_node
|
89
86
|
|
90
|
-
datastream_nodes = env_node.find('x:data')
|
87
|
+
datastream_nodes = env_node.find('x:data', "x:#{EEML_HREF}")
|
91
88
|
# raise NoDataStreams.new, "no datastreams found" if datastream_nodes.empty?
|
92
89
|
env.datastreams = extractDataStreams(datastream_nodes) unless datastream_nodes.empty?
|
93
90
|
|
@@ -105,10 +102,10 @@ module Eeml
|
|
105
102
|
loc.domain = node['domain']
|
106
103
|
loc.disposition = node['disposition']
|
107
104
|
loc.exposure = node['exposure']
|
108
|
-
loc.name = optional_content(node, 'x:name', 'name')
|
109
|
-
loc.latitude = optional_content(node, 'x:lat', 'lat')
|
110
|
-
loc.longitude = optional_content(node, 'x:lon', 'lon')
|
111
|
-
loc.elevation = optional_content(node, 'x:ele', 'ele')
|
105
|
+
loc.name = optional_content(node, 'x:name', 'name', "x:#{EEML_HREF}")
|
106
|
+
loc.latitude = optional_content(node, 'x:lat', 'lat', "x:#{EEML_HREF}")
|
107
|
+
loc.longitude = optional_content(node, 'x:lon', 'lon', "x:#{EEML_HREF}")
|
108
|
+
loc.elevation = optional_content(node, 'x:ele', 'ele', "x:#{EEML_HREF}")
|
112
109
|
return loc
|
113
110
|
end
|
114
111
|
|
@@ -142,11 +139,11 @@ module Eeml
|
|
142
139
|
data = DataStream.new
|
143
140
|
raise MissingAttribute.new(node.name, 'id') if node['id'].nil?
|
144
141
|
data.identifier = node['id']
|
145
|
-
node.find('x:tag').each do |tag_node|
|
142
|
+
node.find('x:tag', "x:#{EEML_HREF}").each do |tag_node|
|
146
143
|
data.tags << tag_node.content
|
147
144
|
end
|
148
145
|
|
149
|
-
value_nodes = node.find('x:value')
|
146
|
+
value_nodes = node.find('x:value', "x:#{EEML_HREF}")
|
150
147
|
raise exception_for_node(node, DataMissingValue, "Data node is missing value node.") if value_nodes.empty?
|
151
148
|
raise exception_for_node(node, DataHasMultipleValues, "Data node has multiple 'value' nodes.") if value_nodes.size > 1
|
152
149
|
|
@@ -155,7 +152,7 @@ module Eeml
|
|
155
152
|
data.max_value = value_node['maxValue']
|
156
153
|
data.value = value_node.content
|
157
154
|
|
158
|
-
unit_nodes = node.find('x:unit')
|
155
|
+
unit_nodes = node.find('x:unit', "x:#{EEML_HREF}")
|
159
156
|
raise exception_for_node(node, DataHasMultipleUnits, "Data node has multiple 'unit' nodes.") if unit_nodes.size > 1
|
160
157
|
|
161
158
|
unit_node = unit_nodes.first
|
@@ -172,16 +169,16 @@ module Eeml
|
|
172
169
|
#Consider mixing these in to the libxml parser for more readable code
|
173
170
|
|
174
171
|
#raises MissingNode if the node isn't there
|
175
|
-
def mandatory_content(base_node, xpath, description)
|
176
|
-
node = base_node.find_first(xpath)
|
172
|
+
def mandatory_content(base_node, xpath, description, nslist = nil)
|
173
|
+
node = base_node.find_first(xpath, nslist)
|
177
174
|
raise(MissingNode.new(node_name_or_root(base_node), description, xpath)) if node.nil?
|
178
175
|
return node.content
|
179
176
|
end
|
180
177
|
|
181
178
|
#returns the node's content, or the given default if the node isn't there (default itself defaults to nil)
|
182
179
|
#description isn't used, but keeps our signature same as mandatory_content(), up to that point.
|
183
|
-
def optional_content(base_node, xpath, description, default = nil)
|
184
|
-
node = base_node.find_first(xpath)
|
180
|
+
def optional_content(base_node, xpath, description, nslist = nil, default = nil)
|
181
|
+
node = base_node.find_first(xpath, nslist)
|
185
182
|
return node.nil? ? default : node.content
|
186
183
|
end
|
187
184
|
|
@@ -192,8 +189,8 @@ module Eeml
|
|
192
189
|
node.respond_to?(:name) ? node.name : 'root'
|
193
190
|
end
|
194
191
|
|
195
|
-
def find_first_node_or_fail(base_node, xpath, description)
|
196
|
-
node = base_node.find_first(xpath)
|
192
|
+
def find_first_node_or_fail(base_node, xpath, description, nslist = nil)
|
193
|
+
node = base_node.find_first(xpath, nslist)
|
197
194
|
raise(MissingNode.new(node_name_or_root(base_node), description, xpath)) if node.nil?
|
198
195
|
return node
|
199
196
|
end
|
data/lib/eeml.rb
CHANGED
@@ -0,0 +1,29 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<eeml:eeml xmlns:eeml="http://www.eeml.org/xsd/005"
|
3
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
4
|
+
xsi:schemaLocation="http://www.eeml.org/xsd/005 http://www.eeml.org/xsd/005/005.xsd" version="5">
|
5
|
+
<eeml:environment updated="2007-05-04T18:13:51.0Z" creator="http://www.haque.co.uk" id="1">
|
6
|
+
<eeml:title>A Room Somewhere</eeml:title>
|
7
|
+
<eeml:feed>http://www.pachube.com/feeds/1.xml</eeml:feed>
|
8
|
+
<eeml:status>frozen</eeml:status>
|
9
|
+
<eeml:description>This is a room somewhere</eeml:description>
|
10
|
+
<eeml:icon>http://www.roomsomewhere/icon.png</eeml:icon>
|
11
|
+
<eeml:website>http://www.roomsomewhere/</eeml:website>
|
12
|
+
<eeml:location exposure="indoor" domain="physical" disposition="fixed">
|
13
|
+
<eeml:name>My Room</eeml:name>
|
14
|
+
<eeml:lat>32.4</eeml:lat>
|
15
|
+
<eeml:lon>22.7</eeml:lon>
|
16
|
+
<eeml:ele>0.2</eeml:ele>
|
17
|
+
</eeml:location>
|
18
|
+
<eeml:data id="0">
|
19
|
+
<eeml:tag>temperature</eeml:tag>
|
20
|
+
<eeml:tag>heat</eeml:tag>
|
21
|
+
<eeml:value maxValue="48.0" minValue="23.0">36.2</eeml:value>
|
22
|
+
<eeml:unit symbol="C" type="basicSI">Celsius</eeml:unit>
|
23
|
+
</eeml:data>
|
24
|
+
<eeml:data id="1">
|
25
|
+
<eeml:tag>nearest_avatar</eeml:tag>
|
26
|
+
<eeml:value>Bram Nogah</eeml:value>
|
27
|
+
</eeml:data>
|
28
|
+
</eeml:environment>
|
29
|
+
</eeml:eeml>
|
data/test/test_environment.rb
CHANGED
@@ -163,6 +163,14 @@ class TestEnvironment < Test::Unit::TestCase
|
|
163
163
|
assert_equal "36.2", datastream.value
|
164
164
|
end
|
165
165
|
|
166
|
+
test "ok parsing fully namespaced eeml file" do
|
167
|
+
env = create_env_from_xml_file('complete_namespaced.xml')
|
168
|
+
assert_equal 2, env.datastreams.size
|
169
|
+
|
170
|
+
datastream = env.datastreams[0]
|
171
|
+
assert_equal "36.2", datastream.value
|
172
|
+
end
|
173
|
+
|
166
174
|
test "fails if no default namespace provided" do
|
167
175
|
assert_raise(MissingNamespace) {env = create_env_from_xml_file('no_namespace.xml')}
|
168
176
|
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eeml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Neill Bogie, Sam Mulube
|
@@ -30,7 +30,7 @@ cert_chain:
|
|
30
30
|
yyRwZdVyDdsafg==
|
31
31
|
-----END CERTIFICATE-----
|
32
32
|
|
33
|
-
date: 2009-07-
|
33
|
+
date: 2009-07-08 00:00:00 +01:00
|
34
34
|
default_executable:
|
35
35
|
dependencies:
|
36
36
|
- !ruby/object:Gem::Dependency
|
@@ -109,7 +109,6 @@ extra_rdoc_files:
|
|
109
109
|
- lib/blank.rb
|
110
110
|
files:
|
111
111
|
- example.rb
|
112
|
-
- eeml.gemspec
|
113
112
|
- LICENSE
|
114
113
|
- CHANGELOG
|
115
114
|
- README
|
@@ -122,6 +121,7 @@ files:
|
|
122
121
|
- test/data/doc_2_expected.json
|
123
122
|
- test/data/list.xml
|
124
123
|
- test/data/out_empty.xml
|
124
|
+
- test/data/complete_namespaced.xml
|
125
125
|
- test/data/no_namespace.xml
|
126
126
|
- test/data/doc_1.xml
|
127
127
|
- test/data/doc_1.json
|
@@ -141,6 +141,7 @@ files:
|
|
141
141
|
- schemas/eeml/005.xsd
|
142
142
|
- Rakefile
|
143
143
|
- Manifest
|
144
|
+
- eeml.gemspec
|
144
145
|
has_rdoc: true
|
145
146
|
homepage: ""
|
146
147
|
licenses: []
|
metadata.gz.sig
CHANGED
Binary file
|