eeml 0.0.41 → 0.0.42
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/csv_parser_v2.rb +1 -1
- data/lib/eeml/environment.rb +1 -9
- data/lib/eeml/json_environment_parser_v100.rb +1 -1
- data/lib/eeml/libxml_eeml_parser_v051.rb +2 -1
- data/test/data/doc_1_no_private_element.json +30 -0
- data/test/data/doc_1_no_private_element.xml +32 -0
- data/test/test_environment.rb +28 -12
- metadata +12 -22
- data/.gitignore +0 -9
data/lib/eeml.rb
CHANGED
data/lib/eeml/csv_parser_v2.rb
CHANGED
@@ -6,7 +6,7 @@ module Eeml
|
|
6
6
|
def self.make_environment_from_csv(csv_content)
|
7
7
|
csv = LightCsv.parse(strip_content(csv_content))
|
8
8
|
environment = Environment.new(:csv_version => 'v2')
|
9
|
-
|
9
|
+
environment.private = nil
|
10
10
|
csv = strip_content(csv)
|
11
11
|
|
12
12
|
datastreams = csv.collect do |datastream|
|
data/lib/eeml/environment.rb
CHANGED
@@ -105,7 +105,7 @@ module Eeml
|
|
105
105
|
attr_accessor :csv_version
|
106
106
|
attr_accessor :datastreams
|
107
107
|
attr_accessor :tags, :has_tag_element
|
108
|
-
|
108
|
+
attr_accessor :private
|
109
109
|
|
110
110
|
# Create a new Environment object by passing parameters in a hash (just
|
111
111
|
# like creating an ActiveRecord object)
|
@@ -186,14 +186,6 @@ module Eeml
|
|
186
186
|
end
|
187
187
|
end
|
188
188
|
|
189
|
-
def private
|
190
|
-
if @private
|
191
|
-
return true
|
192
|
-
else
|
193
|
-
return false
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
189
|
private
|
198
190
|
|
199
191
|
def self.detect_csv_version(version, csv)
|
@@ -12,7 +12,7 @@ module Eeml
|
|
12
12
|
:icon => env_hash["icon"],
|
13
13
|
:status => env_hash["status"],
|
14
14
|
:identifier => env_hash["id"],
|
15
|
-
:private => env_hash["private"].to_s == "true",
|
15
|
+
:private => (env_hash["private"].nil? ? nil : env_hash["private"].to_s == "true"),
|
16
16
|
:publisher => env_hash["publisher"],
|
17
17
|
:creator => env_hash["creator"])
|
18
18
|
|
@@ -79,7 +79,8 @@ module Eeml
|
|
79
79
|
env.status = optional_content(env_node, 'x:status', 'status', "x:#{@@eeml_version[:href]}")
|
80
80
|
env.email = optional_content(env_node, 'x:email', 'email', "x:#{@@eeml_version[:href]}")
|
81
81
|
env.icon = optional_content(env_node, 'x:icon', 'icon', "x:#{@@eeml_version[:href]}")
|
82
|
-
|
82
|
+
private_elem = optional_content(env_node, 'x:private', 'private', "x:#{@@eeml_version[:href]}")
|
83
|
+
env.private = (private_elem.nil? ? nil : private_elem == "true")
|
83
84
|
|
84
85
|
#find_first_node_or_fail(env_node, 'x:location', 'location')
|
85
86
|
loc_node = env_node.find_first('x:location', "x:#{@@eeml_version[:href]}")
|
@@ -0,0 +1,30 @@
|
|
1
|
+
{"datastreams":[
|
2
|
+
{"tags":["tagD0"],
|
3
|
+
"value":{"current_value":"0","min_value":"-9999.0","max_value":"1022.0"},
|
4
|
+
"unit":{"type":"basicSI","label":"Celsius","symbol":"C"},
|
5
|
+
"id":"0"},
|
6
|
+
{"value":{"current_value":"33","min_value":"0.0","max_value":"1023.0"},
|
7
|
+
"id":"1"},
|
8
|
+
{"tags":["tagD2a","tagD2b","tagD2c"],
|
9
|
+
"value":{"current_value":"42.1","min_value":"23.4","max_value":"1021.0"},
|
10
|
+
"id":"2"}
|
11
|
+
],
|
12
|
+
"description":"description here",
|
13
|
+
"updated":"2009-02-11T10:56:56Z",
|
14
|
+
"status":"frozen",
|
15
|
+
"website":"http:\/\/example.com\/studio\/",
|
16
|
+
"email":"someone@example.com",
|
17
|
+
"feed":"http:\/\/example.com\/api\/1247.xml",
|
18
|
+
"location":{
|
19
|
+
"lat":"50.1",
|
20
|
+
"lon":"48.7",
|
21
|
+
"ele":"1.34",
|
22
|
+
"name":"Up on the roof (somewhere)",
|
23
|
+
"domain":"physical",
|
24
|
+
"exposure":"outdoor",
|
25
|
+
"disposition":"mobile"
|
26
|
+
},
|
27
|
+
"icon":"http:\/\/example.com\/some\/icon.gif",
|
28
|
+
"id":"1247",
|
29
|
+
"title":"title here",
|
30
|
+
"version":"1.0.0"}
|
@@ -0,0 +1,32 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<eeml xmlns="http://www.eeml.org/xsd/0.5.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="0.5.1" xsi:schemaLocation="http://www.eeml.org/xsd/0.5.1 http://www.eeml.org/xsd/0.5.1/0.5.1.xsd">
|
3
|
+
<environment updated="2009-02-11T10:56:56Z" id="1247" creator="http://example.com/creator/">
|
4
|
+
<title>title here</title>
|
5
|
+
<feed>http://example.com/api/1247.xml</feed>
|
6
|
+
<status>frozen</status>
|
7
|
+
<description>description here</description>
|
8
|
+
<icon>http://example.com/some/icon.gif</icon>
|
9
|
+
<website>http://example.com/studio/</website>
|
10
|
+
<email>someone@example.com</email>
|
11
|
+
<location domain="physical" exposure="outdoor" disposition="mobile">
|
12
|
+
<name>Up on the roof (somewhere)</name>
|
13
|
+
<lat>50.1</lat>
|
14
|
+
<lon>48.7</lon>
|
15
|
+
<ele>1.34</ele>
|
16
|
+
</location>
|
17
|
+
<data id="0">
|
18
|
+
<tag>tagD0</tag>
|
19
|
+
<value minValue="-9999.0" maxValue="1022.0">0</value>
|
20
|
+
<unit type="basicSI" symbol="C">Celsius</unit>
|
21
|
+
</data>
|
22
|
+
<data id="1">
|
23
|
+
<value minValue="0.0" maxValue="1023.0">33</value>
|
24
|
+
</data>
|
25
|
+
<data id="2">
|
26
|
+
<tag>tagD2a</tag>
|
27
|
+
<tag>tagD2b</tag>
|
28
|
+
<tag>tagD2c</tag>
|
29
|
+
<value minValue="23.4" maxValue="1021.0">42.1</value>
|
30
|
+
</data>
|
31
|
+
</environment>
|
32
|
+
</eeml>
|
data/test/test_environment.rb
CHANGED
@@ -184,6 +184,21 @@ class TestEnvironment < Test::Unit::TestCase
|
|
184
184
|
assert_equal false, env.private
|
185
185
|
end
|
186
186
|
|
187
|
+
test "captures the `private` attribute as nil if the element is missing for xml" do
|
188
|
+
env = create_env_from_xml_file("doc_1_no_private_element.xml")
|
189
|
+
assert_equal nil, env.private
|
190
|
+
end
|
191
|
+
|
192
|
+
test "captures the `private` attribute as nil if the element is missing for json" do
|
193
|
+
env = create_env_from_json_file("doc_1_no_private_element.json")
|
194
|
+
assert_equal nil, env.private
|
195
|
+
end
|
196
|
+
|
197
|
+
test "captures the `private` attribute as nil if the element is missing for csv" do
|
198
|
+
env = Environment.new_from_csv("one,1\r\ntwo,2", :v2)
|
199
|
+
assert_equal nil, env.private
|
200
|
+
end
|
201
|
+
|
187
202
|
test "ok parsing oddly tagged eeml file" do
|
188
203
|
env = create_env_from_xml_file('difficult_tag.xml')
|
189
204
|
assert_equal 2, env.datastreams.size
|
@@ -487,7 +502,7 @@ class TestEnvironment < Test::Unit::TestCase
|
|
487
502
|
end
|
488
503
|
|
489
504
|
test "parses environment level tags from v1.0.0 json" do
|
490
|
-
env = create_env_from_json_file('
|
505
|
+
env = create_env_from_json_file('environment_tags.json')
|
491
506
|
assert_equal 3, env.datastreams.size
|
492
507
|
|
493
508
|
assert_equal 2, env.tags.size
|
@@ -527,7 +542,7 @@ class TestEnvironment < Test::Unit::TestCase
|
|
527
542
|
|
528
543
|
|
529
544
|
test "sets has_tag_element to false if there are no tag elements" do
|
530
|
-
env = create_env_from_json_file('
|
545
|
+
env = create_env_from_json_file('environment_no_tags.json')
|
531
546
|
assert_equal 3, env.datastreams.size
|
532
547
|
|
533
548
|
assert_equal false, env.has_tag_element
|
@@ -537,7 +552,7 @@ class TestEnvironment < Test::Unit::TestCase
|
|
537
552
|
end
|
538
553
|
|
539
554
|
test "sets has_tag_element to true if there are empty tag elements" do
|
540
|
-
env = create_env_from_json_file('
|
555
|
+
env = create_env_from_json_file('environment_empty_tags.json')
|
541
556
|
assert_equal 3, env.datastreams.size
|
542
557
|
|
543
558
|
assert_equal true, env.has_tag_element
|
@@ -622,30 +637,30 @@ class TestEnvironment < Test::Unit::TestCase
|
|
622
637
|
end
|
623
638
|
|
624
639
|
test "captures `private` attribute when parsing old json" do
|
625
|
-
env = create_env_from_json_file("
|
640
|
+
env = create_env_from_json_file("doc_1_private.json")
|
626
641
|
assert_not_nil env
|
627
642
|
assert_equal true, env.private
|
628
643
|
end
|
629
644
|
|
630
645
|
test "captures the `private` attribute as false if present and false when parsing old json" do
|
631
|
-
env = create_env_from_json_file("
|
646
|
+
env = create_env_from_json_file("doc_1_non_private.json")
|
632
647
|
assert_equal false, env.private
|
633
648
|
end
|
634
649
|
|
635
650
|
test "captures `private` attribute when parsing v6 json" do
|
636
|
-
env = create_env_from_json_file("
|
651
|
+
env = create_env_from_json_file("doc_1_v6_private.json")
|
637
652
|
assert_not_nil env
|
638
653
|
assert_equal true, env.private
|
639
654
|
end
|
640
655
|
|
641
656
|
test "captures `private` attribute when parsing 1.0.0 json" do
|
642
|
-
env = create_env_from_json_file("
|
657
|
+
env = create_env_from_json_file("doc_1_v1-0-0.json")
|
643
658
|
assert_not_nil env
|
644
659
|
assert_equal false, env.private
|
645
660
|
end
|
646
661
|
|
647
662
|
test "captures the `private` attribute as false if present and false when parsing v6 json" do
|
648
|
-
env = create_env_from_json_file("
|
663
|
+
env = create_env_from_json_file("doc_1_v6_non_private.json")
|
649
664
|
assert_not_nil env
|
650
665
|
assert_equal false, env.private
|
651
666
|
end
|
@@ -809,18 +824,19 @@ CSV
|
|
809
824
|
end
|
810
825
|
|
811
826
|
def create_env_from_json_file_one
|
812
|
-
return create_env_from_json_file('
|
827
|
+
return create_env_from_json_file('doc_1.json')
|
813
828
|
end
|
814
829
|
|
815
830
|
def create_env_from_json_v6_file_one
|
816
|
-
return create_env_from_json_file('
|
831
|
+
return create_env_from_json_file('doc_1_v6.json')
|
817
832
|
end
|
818
833
|
|
819
834
|
def create_env_from_json_v100_file_one
|
820
|
-
return create_env_from_json_file('
|
835
|
+
return create_env_from_json_file('doc_1_v1-0-0.json')
|
821
836
|
end
|
822
837
|
|
823
|
-
def create_env_from_json_file(
|
838
|
+
def create_env_from_json_file(test_file)
|
839
|
+
filename = 'test/data/' + test_file
|
824
840
|
json = File.read(filename)
|
825
841
|
return Environment.new_from_json(json)
|
826
842
|
end
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eeml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 77
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
7
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
8
|
+
- 42
|
9
|
+
version: 0.0.42
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Neill Bogie
|
@@ -18,18 +17,16 @@ autorequire:
|
|
18
17
|
bindir: bin
|
19
18
|
cert_chain: []
|
20
19
|
|
21
|
-
date: 2011-
|
20
|
+
date: 2011-06-01 00:00:00 +00:00
|
22
21
|
default_executable:
|
23
22
|
dependencies:
|
24
23
|
- !ruby/object:Gem::Dependency
|
25
24
|
name: libxml-ruby
|
26
25
|
prerelease: false
|
27
26
|
requirement: &id001 !ruby/object:Gem::Requirement
|
28
|
-
none: false
|
29
27
|
requirements:
|
30
28
|
- - ">="
|
31
29
|
- !ruby/object:Gem::Version
|
32
|
-
hash: 21
|
33
30
|
segments:
|
34
31
|
- 1
|
35
32
|
- 1
|
@@ -41,11 +38,9 @@ dependencies:
|
|
41
38
|
name: yajl-ruby
|
42
39
|
prerelease: false
|
43
40
|
requirement: &id002 !ruby/object:Gem::Requirement
|
44
|
-
none: false
|
45
41
|
requirements:
|
46
42
|
- - ">="
|
47
43
|
- !ruby/object:Gem::Version
|
48
|
-
hash: 61
|
49
44
|
segments:
|
50
45
|
- 0
|
51
46
|
- 8
|
@@ -57,11 +52,9 @@ dependencies:
|
|
57
52
|
name: lightcsv
|
58
53
|
prerelease: false
|
59
54
|
requirement: &id003 !ruby/object:Gem::Requirement
|
60
|
-
none: false
|
61
55
|
requirements:
|
62
56
|
- - ">="
|
63
57
|
- !ruby/object:Gem::Version
|
64
|
-
hash: 19
|
65
58
|
segments:
|
66
59
|
- 0
|
67
60
|
- 2
|
@@ -79,7 +72,6 @@ extra_rdoc_files:
|
|
79
72
|
- LICENSE
|
80
73
|
- README
|
81
74
|
files:
|
82
|
-
- .gitignore
|
83
75
|
- CHANGELOG
|
84
76
|
- LICENSE
|
85
77
|
- Manifest
|
@@ -108,6 +100,8 @@ files:
|
|
108
100
|
- test/data/difficult_tag.xml
|
109
101
|
- test/data/doc_1.json
|
110
102
|
- test/data/doc_1.xml
|
103
|
+
- test/data/doc_1_no_private_element.json
|
104
|
+
- test/data/doc_1_no_private_element.xml
|
111
105
|
- test/data/doc_1_non_private.json
|
112
106
|
- test/data/doc_1_non_private.xml
|
113
107
|
- test/data/doc_1_private.json
|
@@ -143,40 +137,36 @@ homepage:
|
|
143
137
|
licenses: []
|
144
138
|
|
145
139
|
post_install_message:
|
146
|
-
rdoc_options:
|
147
|
-
|
140
|
+
rdoc_options: []
|
141
|
+
|
148
142
|
require_paths:
|
149
143
|
- lib
|
150
144
|
required_ruby_version: !ruby/object:Gem::Requirement
|
151
|
-
none: false
|
152
145
|
requirements:
|
153
146
|
- - ">="
|
154
147
|
- !ruby/object:Gem::Version
|
155
|
-
hash: 3
|
156
148
|
segments:
|
157
149
|
- 0
|
158
150
|
version: "0"
|
159
151
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
160
|
-
none: false
|
161
152
|
requirements:
|
162
153
|
- - ">="
|
163
154
|
- !ruby/object:Gem::Version
|
164
|
-
hash: 3
|
165
155
|
segments:
|
166
156
|
- 0
|
167
157
|
version: "0"
|
168
158
|
requirements: []
|
169
159
|
|
170
160
|
rubyforge_project:
|
171
|
-
rubygems_version: 1.3.
|
161
|
+
rubygems_version: 1.3.6
|
172
162
|
signing_key:
|
173
163
|
specification_version: 3
|
174
164
|
summary: Simple little library for programmatically manipulating EEML documents.
|
175
165
|
test_files:
|
176
166
|
- test/libxml_test_helper.rb
|
177
|
-
- test/test_libxml_test_helper.rb
|
178
|
-
- test/test_libxml_eeml_parser_v005.rb
|
179
|
-
- test/test_csv_parser_v2.rb
|
180
|
-
- test/test_helper.rb
|
181
167
|
- test/test_csv_parser_v1.rb
|
168
|
+
- test/test_csv_parser_v2.rb
|
182
169
|
- test/test_environment.rb
|
170
|
+
- test/test_helper.rb
|
171
|
+
- test/test_libxml_eeml_parser_v005.rb
|
172
|
+
- test/test_libxml_test_helper.rb
|