eeml 0.0.14 → 0.0.17
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/CHANGELOG +18 -0
- data/README +2 -0
- data/Rakefile +1 -1
- data/lib/eeml/constants.rb +4 -0
- data/lib/eeml/environment_builder.rb +4 -1
- data/lib/eeml/json_environment_parser_v100.rb +82 -0
- data/lib/eeml.rb +1 -1
- data/test/data/doc_1_v1-0-0.json +34 -0
- data/test/test_environment.rb +68 -0
- metadata +9 -6
data/CHANGELOG
CHANGED
@@ -1,3 +1,21 @@
|
|
1
|
+
commit 245dae9ae8e246d3f933106e70df4eadb33823fe
|
2
|
+
Author: Levent Ali <lebreeze@gmail.com>
|
3
|
+
Date: Fri Jul 2 16:03:27 2010 +0100
|
4
|
+
|
5
|
+
Version 0.0.17
|
6
|
+
|
7
|
+
JSON version 0.6rc1 bumped to 1.0.0 (as not tied to eeml directly)
|
8
|
+
JSON 1.0.0 takes at instead of recorded_at
|
9
|
+
|
10
|
+
commit b2829c7df6eea4fb5be3c6834d56d70f472aba9b
|
11
|
+
Author: Levent Ali <lebreeze@gmail.com>
|
12
|
+
Date: Thu Jul 1 17:41:23 2010 +0100
|
13
|
+
|
14
|
+
Version 0.0.15
|
15
|
+
|
16
|
+
Added functionality to parse json v0.6-rc1
|
17
|
+
Updating readme on building gem / gemspec
|
18
|
+
|
1
19
|
commit 926ef3400b50ee441f2c48951ad1e5d1fd4f0549
|
2
20
|
Author: Sam Mulube <sam.mulube@gmail.com>
|
3
21
|
Date: Wed Jun 24 23:47:25 2009 +0100
|
data/README
CHANGED
@@ -8,3 +8,5 @@ Library for simplifying the creation and manipulation of EEML documents, primari
|
|
8
8
|
ruby objects that can be used programmatically. Also provides parsing and output of the JSON format used by pachube.com.
|
9
9
|
|
10
10
|
== USAGE
|
11
|
+
|
12
|
+
rake build - will create gemspec and gem file in pkg/
|
data/Rakefile
CHANGED
@@ -10,7 +10,7 @@ begin
|
|
10
10
|
gem.summary = "Simple little library for programmatically manipulating EEML documents."
|
11
11
|
gem.description = "Simple little library for programmatically manipulating EEML documents, in particular this library is designed to work with the Pachube web service."
|
12
12
|
gem.email = "sam.mulube@gmail.com"
|
13
|
-
gem.authors = ["Neill Bogie", "Sam Mulube"]
|
13
|
+
gem.authors = ["Neill Bogie", "Sam Mulube", "Levent Ali"]
|
14
14
|
gem.version = Eeml::VERSION
|
15
15
|
gem.add_dependency("libxml-ruby", ">=1.1.3")
|
16
16
|
gem.add_dependency("json", ">=1.4.3")
|
data/lib/eeml/constants.rb
CHANGED
@@ -9,6 +9,10 @@ module Eeml
|
|
9
9
|
XSI_NAMESPACE = "http://www.w3.org/2001/XMLSchema-instance"
|
10
10
|
|
11
11
|
EEML6_VERSION = "0.6-alpha1"
|
12
|
+
|
13
|
+
# Not calling this EEML as json is not part of the eeml spec
|
14
|
+
JSON_1_0_0_VERSION = "1.0.0"
|
15
|
+
# EEML6_RC1_VERSION = "0.6-rc1"
|
12
16
|
end
|
13
17
|
end
|
14
18
|
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'eeml/libxml_eeml_parser_v005'
|
2
2
|
require 'eeml/json_environment_parser_v005'
|
3
3
|
require 'eeml/json_environment_parser_v006'
|
4
|
+
require 'eeml/json_environment_parser_v100'
|
4
5
|
|
5
6
|
module Eeml
|
6
7
|
class EnvironmentBuilder # :nodoc:
|
@@ -19,10 +20,12 @@ module Eeml
|
|
19
20
|
json = JSON.parse(json_str)
|
20
21
|
if json["version"].to_i == Constants::EEML5_VERSION.to_i
|
21
22
|
parser = JsonEnvironmentParserV005.new
|
23
|
+
elsif json["version"] == Constants::JSON_1_0_0_VERSION
|
24
|
+
parser = JsonEnvironmentParserV100.new
|
22
25
|
elsif json["version"].to_f == Constants::EEML6_VERSION.to_f
|
23
26
|
parser = JsonEnvironmentParserV006.new
|
24
27
|
else
|
25
|
-
raise "Invalid version specification. Permitted versions are #{Constants::EEML5_VERSION} and #{Constants::
|
28
|
+
raise "Invalid version specification. Permitted versions are #{Constants::EEML5_VERSION}, #{Constants::EEML6_VERSION} and #{Constants::JSON_1_0_0_VERSION}"
|
26
29
|
end
|
27
30
|
return parser.make_environment_from_hash(json)
|
28
31
|
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module Eeml
|
2
|
+
# A parser for json environments based on the EEML 5 specification.
|
3
|
+
class JsonEnvironmentParserV100 # :nodoc:
|
4
|
+
include Exceptions
|
5
|
+
|
6
|
+
def make_environment_from_hash(env_hash)
|
7
|
+
env = Environment.new(:title => env_hash["title"],
|
8
|
+
:description => env_hash["description"],
|
9
|
+
:feed_url => env_hash["feed"],
|
10
|
+
:website => env_hash["website"],
|
11
|
+
:email => env_hash["email"],
|
12
|
+
:icon => env_hash["icon"],
|
13
|
+
:status => env_hash["status"],
|
14
|
+
:identifier => env_hash["id"],
|
15
|
+
:private => env_hash["private"])
|
16
|
+
|
17
|
+
env.updated = Time.gm(*ParseDate.parsedate(env_hash['updated'])) unless env_hash['updated'].nil?
|
18
|
+
|
19
|
+
env.location = buildLocation(env_hash)
|
20
|
+
|
21
|
+
env.datastreams = buildDatastreams(env_hash)
|
22
|
+
|
23
|
+
return env
|
24
|
+
end
|
25
|
+
|
26
|
+
def make_environment_from_json(json_str)
|
27
|
+
env_hash = JSON.parse(json_str)
|
28
|
+
return make_environment_from_hash(env_hash)
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def buildLocation(env_hash)
|
34
|
+
location_hash = env_hash["location"]
|
35
|
+
return if location_hash.nil?
|
36
|
+
Location.new(:name => location_hash["name"],
|
37
|
+
:latitude => location_hash["lat"],
|
38
|
+
:longitude => location_hash["lon"],
|
39
|
+
:elevation => location_hash["ele"],
|
40
|
+
:domain => location_hash["domain"],
|
41
|
+
:disposition => location_hash["disposition"],
|
42
|
+
:exposure => location_hash["exposure"])
|
43
|
+
end
|
44
|
+
|
45
|
+
def buildDatastreams(env_hash)
|
46
|
+
datastreams_hash = env_hash["datastreams"]
|
47
|
+
return if datastreams_hash.nil?
|
48
|
+
datastreams = []
|
49
|
+
datastreams_hash.each do |datastream_hash|
|
50
|
+
datastream = DataStream.new
|
51
|
+
raise MissingAttribute.new('id', "data") if datastream_hash['id'].nil?
|
52
|
+
datastream.identifier = datastream_hash['id']
|
53
|
+
datastream.tags = datastream_hash['tags'] unless datastream_hash['tags'].nil?
|
54
|
+
|
55
|
+
values_arr = datastream_hash["values"]
|
56
|
+
|
57
|
+
raise DataMissingValue if values_arr.nil?
|
58
|
+
|
59
|
+
values_arr.each do |v|
|
60
|
+
value = Value.new(:value => v["value"],
|
61
|
+
:min_value => datastream_hash["min_value"],
|
62
|
+
:max_value => datastream_hash["max_value"],
|
63
|
+
:recorded_at => v["at"])
|
64
|
+
|
65
|
+
datastream.add_value(value)
|
66
|
+
end
|
67
|
+
|
68
|
+
unit_hash = datastream_hash["unit"]
|
69
|
+
unless unit_hash.nil?
|
70
|
+
datastream.unit_symbol = unit_hash["symbol"]
|
71
|
+
datastream.unit_type = unit_hash["type"]
|
72
|
+
datastream.unit_value = unit_hash["label"]
|
73
|
+
end
|
74
|
+
|
75
|
+
datastreams << datastream
|
76
|
+
end
|
77
|
+
return datastreams
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
|
data/lib/eeml.rb
CHANGED
@@ -0,0 +1,34 @@
|
|
1
|
+
{"datastreams":[
|
2
|
+
{"tags":["tagD0"],
|
3
|
+
"values":[{"value":"0","at":"2009-02-11T10:56:56Z"}],
|
4
|
+
"min_value":"-9999.0",
|
5
|
+
"max_value":"1022.0",
|
6
|
+
"unit":{"type":"basicSI","label":"Celsius","symbol":"C"},
|
7
|
+
"id":"0"},
|
8
|
+
{"values":[{"value":"33","at":"2009-02-11T10:56:55Z"}],
|
9
|
+
"min_value":"0.0","max_value":"1023.0",
|
10
|
+
"id":"1"},
|
11
|
+
{"tags":["tagD2a","tagD2b","tagD2c"],
|
12
|
+
"values":[{"value":"42.1","at":"2009-02-11T10:55:10Z"}],
|
13
|
+
"min_value":"23.4","max_value":"1021.0",
|
14
|
+
"id":"2"}
|
15
|
+
],
|
16
|
+
"description":"description here",
|
17
|
+
"updated":"2010-02-11T10:56:56Z",
|
18
|
+
"status":"frozen",
|
19
|
+
"website":"http:\/\/example.com\/studio\/",
|
20
|
+
"email":"someone@example.com",
|
21
|
+
"feed":"http:\/\/example.com\/api\/1247.xml",
|
22
|
+
"location":{
|
23
|
+
"lat":"50.1",
|
24
|
+
"lon":"48.7",
|
25
|
+
"ele":"1.34",
|
26
|
+
"name":"Up on the roof (somewhere)",
|
27
|
+
"domain":"physical",
|
28
|
+
"exposure":"outdoor",
|
29
|
+
"disposition":"mobile"
|
30
|
+
},
|
31
|
+
"icon":"http:\/\/example.com\/some\/icon.gif",
|
32
|
+
"id":"1247",
|
33
|
+
"title":"title here",
|
34
|
+
"version":"1.0.0"}
|
data/test/test_environment.rb
CHANGED
@@ -365,6 +365,70 @@ class TestEnvironment < Test::Unit::TestCase
|
|
365
365
|
end
|
366
366
|
end
|
367
367
|
|
368
|
+
test "parses a v1.0.0 input file ok" do
|
369
|
+
env = create_env_from_json_v100_file_one
|
370
|
+
assert_not_nil env
|
371
|
+
assert_instance_of Environment, env
|
372
|
+
assert_equal('title here', env.title)
|
373
|
+
assert_equal('description here', env.description)
|
374
|
+
assert_equal('http://example.com/api/1247.xml', env.feed_url)
|
375
|
+
assert_equal('http://example.com/studio/', env.website)
|
376
|
+
assert_equal('frozen', env.status)
|
377
|
+
assert_equal('someone@example.com', env.email)
|
378
|
+
assert_equal('http://example.com/some/icon.gif', env.icon)
|
379
|
+
|
380
|
+
#env attrs
|
381
|
+
assert_equal('1247', env.identifier)
|
382
|
+
assert_equal('2010-02-11T10:56:56Z', env.updated.utc.iso8601)
|
383
|
+
end
|
384
|
+
|
385
|
+
test "location parses ok from json when parsing a v1.0.0 file" do
|
386
|
+
env = create_env_from_json_v100_file_one
|
387
|
+
assert_not_nil env.location
|
388
|
+
location = env.location
|
389
|
+
assert_equal "Up on the roof (somewhere)", location.name
|
390
|
+
assert_equal "50.1", location.latitude
|
391
|
+
assert_equal "48.7", location.longitude
|
392
|
+
assert_equal "1.34", location.elevation
|
393
|
+
assert_equal "physical", location.domain
|
394
|
+
assert_equal "outdoor", location.exposure
|
395
|
+
assert_equal "mobile", location.disposition
|
396
|
+
end
|
397
|
+
|
398
|
+
test "datastreams parse ok from v1.0.0 json" do
|
399
|
+
env = create_env_from_json_v100_file_one
|
400
|
+
assert_equal 3, env.datastreams.size
|
401
|
+
|
402
|
+
#the expected values for the datastreams in the test doc
|
403
|
+
expectations_list = [
|
404
|
+
#id, tag array, min, max, value, unit_symbol, unit_type, unit_value
|
405
|
+
['0', ['tagD0'], '-9999.0', '1022.0', '0', 'C', 'basicSI', 'Celsius', '2009-02-11T10:56:56Z'],
|
406
|
+
['1', [], '0.0', '1023.0', '33', nil, nil, nil, '2009-02-11T10:56:55Z'],
|
407
|
+
['2', ['tagD2a', 'tagD2b', 'tagD2c'], '23.4', '1021.0', '42.1', nil, nil, nil, '2009-02-11T10:55:10Z']
|
408
|
+
]
|
409
|
+
env.datastreams.each_with_index do |ds, i|
|
410
|
+
|
411
|
+
e_identifier, e_tags, e_min_value, e_max_value, e_value, e_unit_symbol, e_unit_type, e_unit_value, e_value_recorded_at = expectations_list[i]
|
412
|
+
|
413
|
+
assert_equal e_identifier, ds.identifier
|
414
|
+
|
415
|
+
assert_equal e_tags.size, ds.tags.size, "should have right num of tags"
|
416
|
+
|
417
|
+
e_tags.each do |expected_tag|
|
418
|
+
ds.tags.member? expected_tag
|
419
|
+
|
420
|
+
end
|
421
|
+
|
422
|
+
assert_equal e_value_recorded_at, ds.values.last.recorded_at
|
423
|
+
assert_equal e_min_value, ds.min_value
|
424
|
+
assert_equal e_max_value, ds.max_value
|
425
|
+
assert_equal e_value, ds.value
|
426
|
+
assert_equal e_unit_symbol, ds.unit_symbol
|
427
|
+
assert_equal e_unit_type, ds.unit_type
|
428
|
+
assert_equal e_unit_value, ds.unit_value
|
429
|
+
end
|
430
|
+
end
|
431
|
+
|
368
432
|
test "parses a v6 input file ok" do
|
369
433
|
env = create_env_from_json_v6_file_one
|
370
434
|
assert_not_nil env
|
@@ -599,6 +663,10 @@ class TestEnvironment < Test::Unit::TestCase
|
|
599
663
|
return create_env_from_json_file('test/data/doc_1_v6.json')
|
600
664
|
end
|
601
665
|
|
666
|
+
def create_env_from_json_v100_file_one
|
667
|
+
return create_env_from_json_file('test/data/doc_1_v1-0-0.json')
|
668
|
+
end
|
669
|
+
|
602
670
|
def create_env_from_json_file(filename)
|
603
671
|
json = File.read(filename)
|
604
672
|
return Environment.new_from_json(json)
|
metadata
CHANGED
@@ -5,17 +5,18 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 17
|
9
|
+
version: 0.0.17
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Neill Bogie
|
13
13
|
- Sam Mulube
|
14
|
+
- Levent Ali
|
14
15
|
autorequire:
|
15
16
|
bindir: bin
|
16
17
|
cert_chain: []
|
17
18
|
|
18
|
-
date: 2010-
|
19
|
+
date: 2010-07-02 00:00:00 +01:00
|
19
20
|
default_executable:
|
20
21
|
dependencies:
|
21
22
|
- !ruby/object:Gem::Dependency
|
@@ -72,6 +73,7 @@ files:
|
|
72
73
|
- lib/eeml/exceptions.rb
|
73
74
|
- lib/eeml/json_environment_parser_v005.rb
|
74
75
|
- lib/eeml/json_environment_parser_v006.rb
|
76
|
+
- lib/eeml/json_environment_parser_v100.rb
|
75
77
|
- lib/eeml/json_output.rb
|
76
78
|
- lib/eeml/libxml_eeml_output_v005.rb
|
77
79
|
- lib/eeml/libxml_eeml_parser_v005.rb
|
@@ -84,6 +86,7 @@ files:
|
|
84
86
|
- test/data/doc_1.xml
|
85
87
|
- test/data/doc_1_private.json
|
86
88
|
- test/data/doc_1_private.xml
|
89
|
+
- test/data/doc_1_v1-0-0.json
|
87
90
|
- test/data/doc_1_v6.json
|
88
91
|
- test/data/doc_1_v6_private.json
|
89
92
|
- test/data/doc_2.xml
|
@@ -128,8 +131,8 @@ signing_key:
|
|
128
131
|
specification_version: 3
|
129
132
|
summary: Simple little library for programmatically manipulating EEML documents.
|
130
133
|
test_files:
|
131
|
-
- test/
|
134
|
+
- test/test_helper.rb
|
135
|
+
- test/test_libxml_eeml_parser_v005.rb
|
132
136
|
- test/test_libxml_test_helper.rb
|
137
|
+
- test/test_environment.rb
|
133
138
|
- test/libxml_test_helper.rb
|
134
|
-
- test/test_libxml_eeml_parser_v005.rb
|
135
|
-
- test/test_helper.rb
|