eeml 0.0.29 → 0.0.32
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/lib/eeml/constants.rb +4 -4
- data/lib/eeml/csv_parser_v1.rb +2 -3
- data/lib/eeml/csv_parser_v2.rb +4 -2
- data/lib/eeml/environment.rb +8 -0
- data/lib/eeml/environment_builder.rb +8 -6
- data/lib/eeml/exceptions.rb +4 -2
- data/lib/eeml/json_environment_parser_v005.rb +1 -1
- data/lib/eeml/json_environment_parser_v006.rb +1 -1
- data/lib/eeml/json_environment_parser_v100.rb +1 -1
- data/lib/eeml/libxml_eeml_parser_v005.rb +1 -1
- data/lib/eeml/libxml_eeml_parser_v051.rb +1 -1
- data/lib/eeml.rb +1 -1
- data/test/test_environment.rb +39 -0
- metadata +4 -4
data/lib/eeml/constants.rb
CHANGED
@@ -21,7 +21,7 @@ module Eeml
|
|
21
21
|
EEML["0.5.0"] =
|
22
22
|
{
|
23
23
|
:href => 'http://www.eeml.org/xsd/005',
|
24
|
-
:
|
24
|
+
:versions => ['5', '0.5.0'],
|
25
25
|
:schema_location => 'http://www.eeml.org/xsd/005 http://www.eeml.org/xsd/005/005.xsd'
|
26
26
|
}
|
27
27
|
|
@@ -29,18 +29,18 @@ module Eeml
|
|
29
29
|
EEML["0.5.1"] =
|
30
30
|
{
|
31
31
|
:href => 'http://www.eeml.org/xsd/0.5.1',
|
32
|
-
:
|
32
|
+
:versions => '0.5.1',
|
33
33
|
:schema_location => 'http://www.eeml.org/xsd/0.5.1 http://www.eeml.org/xsd/0.5.1/0.5.1.xsd'
|
34
34
|
}
|
35
35
|
|
36
36
|
JSON_API["0.6-alpha"] =
|
37
37
|
{
|
38
|
-
:
|
38
|
+
:versions => ['0.6', '0.6-alpha']
|
39
39
|
}
|
40
40
|
|
41
41
|
JSON_API["1.0.0"] =
|
42
42
|
{
|
43
|
-
:
|
43
|
+
:versions => ['1.0.0']
|
44
44
|
}
|
45
45
|
|
46
46
|
|
data/lib/eeml/csv_parser_v1.rb
CHANGED
@@ -7,9 +7,8 @@ module Eeml
|
|
7
7
|
|
8
8
|
raise(CsvEncodingError, "Currently Pachube can only accept csv for your most recent set of values. You have submitted #{csv.size} rows of data.") unless csv.size == 1
|
9
9
|
|
10
|
-
csv.first.
|
11
|
-
|
12
|
-
end
|
10
|
+
environment.add_datastreams(csv.first.collect { |datastream_value| DataStream.new(:value => datastream_value) })
|
11
|
+
|
13
12
|
environment
|
14
13
|
end
|
15
14
|
end
|
data/lib/eeml/csv_parser_v2.rb
CHANGED
@@ -9,11 +9,13 @@ module Eeml
|
|
9
9
|
|
10
10
|
csv = strip_content(csv)
|
11
11
|
|
12
|
-
csv.
|
12
|
+
datastreams = csv.collect do |datastream|
|
13
13
|
raise(CsvEncodingError, "CSV is invalid. Double check you are properly encoding line breaks.") if datastream.length == 3 && datastream[1].include?('\n')
|
14
14
|
raise(CsvEncodingError, "CSV is invalid. Incorrect number of fields.") if datastream.length != 2
|
15
|
-
|
15
|
+
DataStream.new(:value => datastream.last, :identifier => datastream.first)
|
16
16
|
end
|
17
|
+
environment.add_datastreams(datastreams)
|
18
|
+
|
17
19
|
environment
|
18
20
|
end
|
19
21
|
end
|
data/lib/eeml/environment.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
module Eeml
|
2
2
|
include Eeml::Constants
|
3
|
+
include Eeml::Exceptions
|
3
4
|
|
4
5
|
# One of the component classes of Environment. Represents the location of the environment. Environments can only have a single location object.
|
5
6
|
class Location
|
@@ -124,6 +125,13 @@ module Eeml
|
|
124
125
|
def add_datastream(datastream)
|
125
126
|
#TODO: consider checking for unique identifier
|
126
127
|
datastreams << datastream
|
128
|
+
if dups = datastreams.map(&:identifier).compact.uniq!
|
129
|
+
raise Eeml::Exceptions::DuplicateDataStreams, "Duplicate Datastream IDs: #{dups.join(', ')}"
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
def add_datastreams(array)
|
134
|
+
array.each { |d| add_datastream d }
|
127
135
|
end
|
128
136
|
|
129
137
|
def remove_last_datastream
|
@@ -32,18 +32,20 @@ module Eeml
|
|
32
32
|
|
33
33
|
def self.build_from_json(json_str)
|
34
34
|
json = JSON.parse(json_str)
|
35
|
-
if
|
35
|
+
if Constants::EEML['0.5.0'][:versions].include? json["version"].to_s
|
36
36
|
parser = JsonEnvironmentParserV005.new
|
37
|
-
elsif
|
37
|
+
elsif Constants::EEML['0.5.1'][:versions].include? json["version"].to_s
|
38
|
+
parser = JsonEnvironmentParserV005.new
|
39
|
+
elsif Constants::JSON_API['1.0.0'][:versions].include? json["version"].to_s
|
38
40
|
parser = JsonEnvironmentParserV100.new
|
39
|
-
elsif
|
41
|
+
elsif Constants::JSON_API['0.6-alpha'][:versions].include? json["version"].to_s
|
40
42
|
parser = JsonEnvironmentParserV006.new
|
41
43
|
else
|
42
|
-
raise # raise something so we jump to the rescue block below
|
44
|
+
raise Eeml::Exceptions::BadVersion# raise something so we jump to the rescue block below
|
43
45
|
end
|
44
46
|
return parser.make_environment_from_hash(json)
|
45
|
-
rescue
|
46
|
-
raise JSON::ParserError, "Invalid version specification. Permitted versions are #{Constants::EEML['0.5.0'][:
|
47
|
+
rescue Eeml::Exceptions::BadVersion, TypeError
|
48
|
+
raise JSON::ParserError, "Invalid version specification. Permitted versions are #{Constants::EEML['0.5.0'][:versions].first}, #{Constants::JSON_API["0.6-alpha"][:versions].first} and #{Constants::JSON_API["1.0.0"][:versions].first}"
|
47
49
|
end
|
48
50
|
|
49
51
|
def self.build_from_csv(csv_str, version = :v1)
|
data/lib/eeml/exceptions.rb
CHANGED
@@ -23,9 +23,9 @@ module Eeml
|
|
23
23
|
class DataHasMultipleUnits < BadEeml; end
|
24
24
|
class DataHasMultipleValues < BadEeml; end
|
25
25
|
class NoDataStreams < BadEeml; end
|
26
|
+
class DuplicateDataStreams < BadEeml; end
|
26
27
|
class MissingNamespace < BadEeml; end
|
27
28
|
|
28
|
-
|
29
29
|
#A structured exception which holds info about what was missing and from where.
|
30
30
|
#Note: Some reasons we don't just hold everything in an unstructured exception message:
|
31
31
|
#1. some bits might be useful for dev but not for the public,
|
@@ -57,7 +57,9 @@ module Eeml
|
|
57
57
|
def to_s
|
58
58
|
"Missing attribute '#@attribute_name' from node '#@node_name'"
|
59
59
|
end
|
60
|
-
end
|
60
|
+
end
|
61
|
+
|
62
|
+
class BadVersion < StandardError; end
|
61
63
|
end
|
62
64
|
end
|
63
65
|
|
@@ -87,7 +87,7 @@ module Eeml
|
|
87
87
|
|
88
88
|
datastream_nodes = env_node.find('x:data', "x:#{@@eeml_version[:href]}")
|
89
89
|
# raise NoDataStreams.new, "no datastreams found" if datastream_nodes.empty?
|
90
|
-
env.
|
90
|
+
env.add_datastreams(extractDataStreams(datastream_nodes)) unless datastream_nodes.empty?
|
91
91
|
|
92
92
|
return env
|
93
93
|
end
|
@@ -91,7 +91,7 @@ module Eeml
|
|
91
91
|
|
92
92
|
datastream_nodes = env_node.find('x:data', "x:#{@@eeml_version[:href]}")
|
93
93
|
# raise NoDataStreams.new, "no datastreams found" if datastream_nodes.empty?
|
94
|
-
env.
|
94
|
+
env.add_datastreams(extractDataStreams(datastream_nodes)) unless datastream_nodes.empty?
|
95
95
|
|
96
96
|
return env
|
97
97
|
end
|
data/lib/eeml.rb
CHANGED
data/test/test_environment.rb
CHANGED
@@ -679,6 +679,45 @@ CSV
|
|
679
679
|
assert_equal "CSV version could not be detected", exception.message
|
680
680
|
end
|
681
681
|
|
682
|
+
# --- Other Unit Tests -------------------------------------------------------
|
683
|
+
# --- -------------------------------------------------------
|
684
|
+
# --- Stuff that gets used in lots of places ---------------------------------
|
685
|
+
|
686
|
+
test "environment#add_datastreams should add a group of datastreams" do
|
687
|
+
e = Environment.new
|
688
|
+
values = %w(e1 e2 e3)
|
689
|
+
e.add_datastreams values.collect {|v| DataStream.new(:value => v)}
|
690
|
+
assert_equal values.size, e.datastreams.size
|
691
|
+
end
|
692
|
+
|
693
|
+
test "environment#add_datastreams should raise an exception if passed duplicate datastreams" do
|
694
|
+
e = Environment.new
|
695
|
+
stream_ids = %w(ds1 ds2 ds1 ds3)
|
696
|
+
assert_raise Exceptions::DuplicateDataStreams, "Duplicate Datastream ID: ds1" do
|
697
|
+
e.add_datastreams stream_ids.collect {|id| DataStream.new(:identifier => id)}
|
698
|
+
end
|
699
|
+
end
|
700
|
+
|
701
|
+
test "environment#add_datastreams should raise an exception if datastream ids conflict with existing stream ids" do
|
702
|
+
e = Environment.new
|
703
|
+
stream_ids = %w(ds1 ds2 ds3)
|
704
|
+
e.add_datastreams stream_ids.collect {|id| DataStream.new(:identifier => id)}
|
705
|
+
|
706
|
+
assert_raise Exceptions::DuplicateDataStreams, "Duplicate Datastream ID: ds2" do
|
707
|
+
e.add_datastreams [DataStream.new(:identifier => "ds2")]
|
708
|
+
end
|
709
|
+
end
|
710
|
+
|
711
|
+
test "environment#add_datastream should raise an exception if datastream ids conflict with existing stream ids" do
|
712
|
+
e = Environment.new
|
713
|
+
stream_ids = %w(ds1 ds2 ds3)
|
714
|
+
e.add_datastreams stream_ids.collect {|id| DataStream.new(:identifier => id)}
|
715
|
+
|
716
|
+
assert_raise Exceptions::DuplicateDataStreams, "Duplicate Datastream ID: ds3" do
|
717
|
+
e.add_datastream DataStream.new(:identifier => "ds3")
|
718
|
+
end
|
719
|
+
end
|
720
|
+
|
682
721
|
# --- convenience stuff - don't put tests under here ------------------------------
|
683
722
|
|
684
723
|
def create_env_from_xml_string(string)
|
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: 95
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 32
|
10
|
+
version: 0.0.32
|
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-02-14 00:00:00 +00:00
|
22
22
|
default_executable:
|
23
23
|
dependencies:
|
24
24
|
- !ruby/object:Gem::Dependency
|