eeml 0.0.38 → 0.0.39
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/eeml.rb +1 -1
- data/lib/eeml/environment.rb +4 -2
- data/lib/eeml/json_environment_parser_v005.rb +1 -0
- data/lib/eeml/json_environment_parser_v006.rb +1 -0
- data/lib/eeml/json_environment_parser_v100.rb +3 -1
- data/lib/eeml/libxml_eeml_parser_v005.rb +1 -0
- data/lib/eeml/libxml_eeml_parser_v051.rb +2 -0
- data/test/data/environment_empty_tags.json +44 -0
- data/test/data/environment_no_tags.json +40 -0
- data/test/test_environment.rb +24 -0
- metadata +9 -7
data/lib/eeml.rb
CHANGED
data/lib/eeml/environment.rb
CHANGED
@@ -21,12 +21,13 @@ module Eeml
|
|
21
21
|
# One of the component classes of Environment. Represents an individual datastream, and provides access to it's value
|
22
22
|
# and other attributes. Environments can have zero or more datastreams.
|
23
23
|
class DataStream
|
24
|
-
attr_accessor :identifier, :tags, :unit_symbol, :unit_type, :unit_value
|
24
|
+
attr_accessor :identifier, :tags, :unit_symbol, :unit_type, :unit_value, :has_tag_element
|
25
25
|
attr_accessor :values
|
26
26
|
|
27
27
|
def initialize(options = {})
|
28
28
|
@identifier = options[:identifier]
|
29
29
|
@tags = []
|
30
|
+
@has_tag_element = false
|
30
31
|
@unit_symbol = options[:unit_symbol]
|
31
32
|
@unit_type = options[:unit_type]
|
32
33
|
@unit_value = options[:unit_value]
|
@@ -103,7 +104,7 @@ module Eeml
|
|
103
104
|
attr_accessor :location
|
104
105
|
attr_accessor :csv_version
|
105
106
|
attr_accessor :datastreams
|
106
|
-
attr_accessor :tags
|
107
|
+
attr_accessor :tags, :has_tag_element
|
107
108
|
attr_writer :private
|
108
109
|
|
109
110
|
# Create a new Environment object by passing parameters in a hash (just
|
@@ -123,6 +124,7 @@ module Eeml
|
|
123
124
|
@csv_version = options[:csv_version]
|
124
125
|
@publisher = options[:publisher]
|
125
126
|
@tags = []
|
127
|
+
@has_tag_element = false
|
126
128
|
end
|
127
129
|
|
128
130
|
def add_datastream(datastream)
|
@@ -50,6 +50,7 @@ module Eeml
|
|
50
50
|
datastream = DataStream.new
|
51
51
|
raise MissingAttribute.new('id', "data") if datastream_hash['id'].nil?
|
52
52
|
datastream.identifier = datastream_hash['id']
|
53
|
+
datastream.has_tag_element = !!datastream_hash['tags']
|
53
54
|
datastream.tags = datastream_hash['tags'] unless datastream_hash['tags'].nil?
|
54
55
|
|
55
56
|
value_hash = datastream_hash["value"]
|
@@ -50,6 +50,7 @@ module Eeml
|
|
50
50
|
datastream = DataStream.new
|
51
51
|
raise MissingAttribute.new('id', "data") if datastream_hash['id'].nil?
|
52
52
|
datastream.identifier = datastream_hash['id']
|
53
|
+
datastream.has_tag_element = !!datastream_hash['tags']
|
53
54
|
datastream.tags = datastream_hash['tags'] unless datastream_hash['tags'].nil?
|
54
55
|
|
55
56
|
values_arr = datastream_hash["values"]
|
@@ -17,7 +17,8 @@ module Eeml
|
|
17
17
|
:creator => env_hash["creator"])
|
18
18
|
|
19
19
|
env.updated = Time.gm(*ParseDate.parsedate(env_hash['updated'])) unless env_hash['updated'].nil?
|
20
|
-
|
20
|
+
|
21
|
+
env.has_tag_element = !!env_hash['tags']
|
21
22
|
env.tags = env_hash['tags'] unless env_hash['tags'].nil?
|
22
23
|
|
23
24
|
env.location = buildLocation(env_hash)
|
@@ -54,6 +55,7 @@ module Eeml
|
|
54
55
|
datastream = DataStream.new
|
55
56
|
raise MissingAttribute.new('id', "data") if datastream_hash['id'].nil?
|
56
57
|
datastream.identifier = datastream_hash['id']
|
58
|
+
datastream.has_tag_element = !!datastream_hash['tags']
|
57
59
|
datastream.tags = datastream_hash['tags'] unless datastream_hash['tags'].nil?
|
58
60
|
|
59
61
|
#values_arr = datastream_hash["history"]
|
@@ -142,6 +142,7 @@ module Eeml
|
|
142
142
|
node.find('x:tag', "x:#{@@eeml_version[:href]}").each do |tag_node|
|
143
143
|
data.tags << tag_node.content.strip
|
144
144
|
end
|
145
|
+
data.has_tag_element = true
|
145
146
|
|
146
147
|
value_nodes = node.find('x:value', "x:#{@@eeml_version[:href]}")
|
147
148
|
raise exception_for_node(node, DataMissingValue, "Data node is missing value node.") if value_nodes.empty?
|
@@ -87,6 +87,7 @@ module Eeml
|
|
87
87
|
env_node.find('x:tag', "x:#{@@eeml_version[:href]}").each do |tag_node|
|
88
88
|
env.tags << tag_node.content.strip
|
89
89
|
end
|
90
|
+
env.has_tag_element = true
|
90
91
|
|
91
92
|
datastream_nodes = env_node.find('x:data', "x:#{@@eeml_version[:href]}")
|
92
93
|
# raise NoDataStreams.new, "no datastreams found" if datastream_nodes.empty?
|
@@ -148,6 +149,7 @@ module Eeml
|
|
148
149
|
node.find('x:tag', "x:#{@@eeml_version[:href]}").each do |tag_node|
|
149
150
|
data.tags << tag_node.content.strip
|
150
151
|
end
|
152
|
+
data.has_tag_element = true
|
151
153
|
|
152
154
|
value_nodes = node.find('x:current_value', "x:#{@@eeml_version[:href]}")
|
153
155
|
# raise exception_for_node(node, DataMissingValue, "Data node is missing current_value node.") if value_nodes.empty?
|
@@ -0,0 +1,44 @@
|
|
1
|
+
{"datastreams":[
|
2
|
+
{
|
3
|
+
"current_value":"0",
|
4
|
+
"at":"2009-02-11T10:56:56Z",
|
5
|
+
"min_value":"-9999.0",
|
6
|
+
"max_value":"1022.0",
|
7
|
+
"unit":{"type":"basicSI","label":"Celsius","symbol":"C"},
|
8
|
+
"id":"0",
|
9
|
+
"tags":[]
|
10
|
+
},
|
11
|
+
{
|
12
|
+
"current_value":"33",
|
13
|
+
"at":"2009-02-11T10:56:55Z",
|
14
|
+
"min_value":"0.0","max_value":"1023.0",
|
15
|
+
"id":"1",
|
16
|
+
"tags":[]},
|
17
|
+
{"current_value":"42.1",
|
18
|
+
"at":"2009-02-11T10:55:10Z",
|
19
|
+
"min_value":"23.4","max_value":"1021.0",
|
20
|
+
"id":"2",
|
21
|
+
"tags":[]}
|
22
|
+
],
|
23
|
+
"description":"description here",
|
24
|
+
"updated":"2010-02-11T10:56:56Z",
|
25
|
+
"status":"frozen",
|
26
|
+
"website":"http:\/\/example.com\/studio\/",
|
27
|
+
"email":"someone@example.com",
|
28
|
+
"feed":"http:\/\/example.com\/api\/1247.xml",
|
29
|
+
"location":{
|
30
|
+
"lat":"50.1",
|
31
|
+
"lon":"48.7",
|
32
|
+
"ele":"1.34",
|
33
|
+
"name":"Up on the roof (somewhere)",
|
34
|
+
"domain":"physical",
|
35
|
+
"exposure":"outdoor",
|
36
|
+
"disposition":"mobile"
|
37
|
+
},
|
38
|
+
"icon":"http:\/\/example.com\/some\/icon.gif",
|
39
|
+
"id":"1247",
|
40
|
+
"title":"title here",
|
41
|
+
"version":"1.0.0",
|
42
|
+
"owner":"http:\/\/www.pachube.com\/users\/joe",
|
43
|
+
"publisher":"http:\/\/www.pachube.com",
|
44
|
+
"tags":[]}
|
@@ -0,0 +1,40 @@
|
|
1
|
+
{"datastreams":[
|
2
|
+
{
|
3
|
+
"current_value":"0",
|
4
|
+
"at":"2009-02-11T10:56:56Z",
|
5
|
+
"min_value":"-9999.0",
|
6
|
+
"max_value":"1022.0",
|
7
|
+
"unit":{"type":"basicSI","label":"Celsius","symbol":"C"},
|
8
|
+
"id":"0"
|
9
|
+
},
|
10
|
+
{
|
11
|
+
"current_value":"33",
|
12
|
+
"at":"2009-02-11T10:56:55Z",
|
13
|
+
"min_value":"0.0","max_value":"1023.0",
|
14
|
+
"id":"1"},
|
15
|
+
{"current_value":"42.1",
|
16
|
+
"at":"2009-02-11T10:55:10Z",
|
17
|
+
"min_value":"23.4","max_value":"1021.0",
|
18
|
+
"id":"2"}
|
19
|
+
],
|
20
|
+
"description":"description here",
|
21
|
+
"updated":"2010-02-11T10:56:56Z",
|
22
|
+
"status":"frozen",
|
23
|
+
"website":"http:\/\/example.com\/studio\/",
|
24
|
+
"email":"someone@example.com",
|
25
|
+
"feed":"http:\/\/example.com\/api\/1247.xml",
|
26
|
+
"location":{
|
27
|
+
"lat":"50.1",
|
28
|
+
"lon":"48.7",
|
29
|
+
"ele":"1.34",
|
30
|
+
"name":"Up on the roof (somewhere)",
|
31
|
+
"domain":"physical",
|
32
|
+
"exposure":"outdoor",
|
33
|
+
"disposition":"mobile"
|
34
|
+
},
|
35
|
+
"icon":"http:\/\/example.com\/some\/icon.gif",
|
36
|
+
"id":"1247",
|
37
|
+
"title":"title here",
|
38
|
+
"version":"1.0.0",
|
39
|
+
"owner":"http:\/\/www.pachube.com\/users\/joe",
|
40
|
+
"publisher":"http:\/\/www.pachube.com"}
|
data/test/test_environment.rb
CHANGED
@@ -213,6 +213,7 @@ class TestEnvironment < Test::Unit::TestCase
|
|
213
213
|
assert_equal 'House', env.tags[1]
|
214
214
|
|
215
215
|
assert_equal 1, env.datastreams.size
|
216
|
+
assert_equal true, env.has_tag_element
|
216
217
|
end
|
217
218
|
|
218
219
|
test "creates multiple environments from list xml" do
|
@@ -492,6 +493,27 @@ class TestEnvironment < Test::Unit::TestCase
|
|
492
493
|
assert_equal 2, env.tags.size
|
493
494
|
assert_equal env.tags[0], 'tagE0'
|
494
495
|
assert_equal env.tags[1], 'tagE1'
|
496
|
+
assert_equal true, env.has_tag_element
|
497
|
+
end
|
498
|
+
|
499
|
+
test "sets has_tag_element to false if there are no tag elements" do
|
500
|
+
env = create_env_from_json_file('test/data/environment_no_tags.json')
|
501
|
+
assert_equal 3, env.datastreams.size
|
502
|
+
|
503
|
+
assert_equal false, env.has_tag_element
|
504
|
+
assert_equal env.datastreams[0].has_tag_element, false
|
505
|
+
assert_equal env.datastreams[1].has_tag_element, false
|
506
|
+
assert_equal env.datastreams[2].has_tag_element, false
|
507
|
+
end
|
508
|
+
|
509
|
+
test "sets has_tag_element to true if there are empty tag elements" do
|
510
|
+
env = create_env_from_json_file('test/data/environment_empty_tags.json')
|
511
|
+
assert_equal 3, env.datastreams.size
|
512
|
+
|
513
|
+
assert_equal true, env.has_tag_element
|
514
|
+
assert_equal env.datastreams[0].has_tag_element, true
|
515
|
+
assert_equal env.datastreams[1].has_tag_element, true
|
516
|
+
assert_equal env.datastreams[2].has_tag_element, true
|
495
517
|
end
|
496
518
|
|
497
519
|
test "parses a v6 input file ok" do
|
@@ -509,6 +531,7 @@ class TestEnvironment < Test::Unit::TestCase
|
|
509
531
|
#env attrs
|
510
532
|
assert_equal('1247', env.identifier)
|
511
533
|
assert_equal('2009-02-11T10:56:56Z', env.updated.utc.iso8601)
|
534
|
+
assert_equal false, env.has_tag_element
|
512
535
|
end
|
513
536
|
|
514
537
|
test "location parses ok from json when parsing a v6 file" do
|
@@ -553,6 +576,7 @@ class TestEnvironment < Test::Unit::TestCase
|
|
553
576
|
assert_equal e_unit_symbol, ds.unit_symbol
|
554
577
|
assert_equal e_unit_type, ds.unit_type
|
555
578
|
assert_equal e_unit_value, ds.unit_value
|
579
|
+
assert_equal false, env.has_tag_element
|
556
580
|
end
|
557
581
|
end
|
558
582
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eeml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 81
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 39
|
10
|
+
version: 0.0.39
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Neill Bogie
|
@@ -18,7 +18,7 @@ autorequire:
|
|
18
18
|
bindir: bin
|
19
19
|
cert_chain: []
|
20
20
|
|
21
|
-
date: 2011-
|
21
|
+
date: 2011-05-13 00:00:00 +00:00
|
22
22
|
default_executable:
|
23
23
|
dependencies:
|
24
24
|
- !ruby/object:Gem::Dependency
|
@@ -119,7 +119,9 @@ files:
|
|
119
119
|
- test/data/doc_2.xml
|
120
120
|
- test/data/doc_2_expected.json
|
121
121
|
- test/data/eeml_datastream_051.xml
|
122
|
+
- test/data/environment_empty_tags.json
|
122
123
|
- test/data/environment_minimal_051.xml
|
124
|
+
- test/data/environment_no_tags.json
|
123
125
|
- test/data/environment_tags.json
|
124
126
|
- test/data/environment_tags.xml
|
125
127
|
- test/data/list.xml
|
@@ -168,10 +170,10 @@ signing_key:
|
|
168
170
|
specification_version: 3
|
169
171
|
summary: Simple little library for programmatically manipulating EEML documents.
|
170
172
|
test_files:
|
171
|
-
- test/
|
173
|
+
- test/libxml_test_helper.rb
|
172
174
|
- test/test_libxml_test_helper.rb
|
175
|
+
- test/test_libxml_eeml_parser_v005.rb
|
173
176
|
- test/test_csv_parser_v2.rb
|
177
|
+
- test/test_helper.rb
|
174
178
|
- test/test_csv_parser_v1.rb
|
175
179
|
- test/test_environment.rb
|
176
|
-
- test/libxml_test_helper.rb
|
177
|
-
- test/test_helper.rb
|