eeml 0.0.35 → 0.0.36

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.
@@ -0,0 +1,8 @@
1
+ class Module
2
+ def attr_alias(new_attr, original)
3
+ alias_method(new_attr, original) if method_defined?(original)
4
+ new_writer = "#{new_attr}="
5
+ original_writer = "#{original}="
6
+ alias_method(new_writer, original_writer) if method_defined?(original_writer)
7
+ end
8
+ end
@@ -1,19 +1,7 @@
1
1
  module Eeml
2
2
  module Constants
3
- # LOCAL_EEML5_SCHEMA_LOCATION = "schemas/eeml/005.xsd" # :nodoc:
4
- # EEML5_HREF = "http://www.eeml.org/xsd/005"
5
- # EEML5_VERSION = "5"
6
- # EEML5_SCHEMA_LOCATION = "http://www.eeml.org/xsd/005 http://www.eeml.org/xsd/005/005.xsd"
7
-
8
- # EEML5_NAMESPACE = ":#{EEML5_HREF}"
9
3
  XSI_NAMESPACE = "http://www.w3.org/2001/XMLSchema-instance"
10
4
 
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
-
16
- # EEML6_RC1_VERSION = "0.6-rc1"
17
5
  JSON_API = {}
18
6
  EEML = {}
19
7
 
@@ -93,20 +93,11 @@ module Eeml
93
93
  end
94
94
  end
95
95
 
96
- class Owner
97
- attr_accessor :login, :url
98
-
99
- def initialize(options = {})
100
- @login = options[:login]
101
- @url = options[:url]
102
- end
103
- end
104
-
105
96
  # This class represents the main point of entry to this library. In general we will be creating instances of this class, either
106
97
  # by manually specifying the parameters, or probably more commonly, by passing in either an EEML or JSON formatted string which
107
98
  # will be parsed to initialize the object.
108
99
  class Environment
109
- attr_accessor :identifier, :updated, :creator
100
+ attr_accessor :identifier, :updated, :publisher
110
101
  attr_accessor :title, :description, :feed_url, :website, :email, :icon, :status
111
102
  attr_accessor :owner
112
103
  attr_accessor :location
@@ -114,12 +105,15 @@ module Eeml
114
105
  attr_accessor :datastreams
115
106
  attr_accessor :tags
116
107
  attr_writer :private
108
+ attr_accessor :owner
109
+
110
+ attr_alias :creator, :publisher
117
111
 
118
112
  # Create a new Environment object by passing parameters in a hash (just like creating an ActiveRecord object)
119
113
  def initialize(options = {})
120
114
  @datastreams = []
121
115
  @identifier = options[:identifier]
122
- @creator = options[:creator]
116
+ @publisher = options[:publisher] || options[:creator]
123
117
  @title = options[:title]
124
118
  @status = options[:status]
125
119
  @feed_url = options[:feed_url]
@@ -129,6 +123,7 @@ module Eeml
129
123
  @icon = options[:icon]
130
124
  @private = options[:private]
131
125
  @csv_version = options[:csv_version]
126
+ @owner = options[:owner]
132
127
  @tags = []
133
128
  end
134
129
 
@@ -12,14 +12,14 @@ 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"].to_s == "true",
16
+ :publisher => env_hash["publisher"],
17
+ :owner => env_hash["owner"])
16
18
 
17
19
  env.updated = Time.gm(*ParseDate.parsedate(env_hash['updated'])) unless env_hash['updated'].nil?
18
20
 
19
21
  env.tags = env_hash['tags'] unless env_hash['tags'].nil?
20
22
 
21
- env.owner = buildOwner(env_hash)
22
-
23
23
  env.location = buildLocation(env_hash)
24
24
 
25
25
  env.add_datastreams(buildDatastreams(env_hash))
@@ -34,13 +34,6 @@ module Eeml
34
34
 
35
35
  private
36
36
 
37
- def buildOwner(env_hash)
38
- owner_hash = env_hash["owner"]
39
- return if owner_hash.nil?
40
- Owner.new(:login => owner_hash["login"],
41
- :url => owner_hash["url"])
42
- end
43
-
44
37
  def buildLocation(env_hash)
45
38
  location_hash = env_hash["location"]
46
39
  return if location_hash.nil?
@@ -89,5 +82,3 @@ module Eeml
89
82
  end
90
83
  end
91
84
  end
92
-
93
-
@@ -47,7 +47,6 @@ module Eeml
47
47
  #validation?
48
48
  # seems we have to recreate our XML::Schema object on each invocation
49
49
  # else libxml segfaults very quickly
50
- #doc.validate_schema(XML::Schema.from_string(IO.read(LOCAL_EEML5_SCHEMA_LOCATION)))
51
50
  return doc
52
51
  end
53
52
 
@@ -47,7 +47,6 @@ module Eeml
47
47
  #validation?
48
48
  # seems we have to recreate our XML::Schema object on each invocation
49
49
  # else libxml segfaults very quickly
50
- #doc.validate_schema(XML::Schema.from_string(IO.read(LOCAL_EEML5_SCHEMA_LOCATION)))
51
50
  return doc
52
51
  end
53
52
 
@@ -47,7 +47,6 @@ module Eeml
47
47
  #validation?
48
48
  # seems we have to recreate our XML::Schema object on each invocation
49
49
  # else libxml segfaults very quickly
50
- #doc.validate_schema(XML::Schema.from_string(IO.read(LOCAL_EEML5_SCHEMA_LOCATION)))
51
50
  return doc
52
51
  end
53
52
 
@@ -69,7 +68,7 @@ module Eeml
69
68
  env.identifier = env_node['id']
70
69
  env.updated = Time.parse(env_node['updated']) if !env_node['updated'].nil?
71
70
 
72
- env.creator = env_node['creator']
71
+ env.publisher = env_node['publisher']
73
72
 
74
73
  env.title = optional_content(env_node, 'x:title', 'title', "x:#{@@eeml_version[:href]}")
75
74
  env.feed_url = optional_content(env_node, 'x:feed', 'feed', "x:#{@@eeml_version[:href]}")
@@ -79,9 +78,7 @@ module Eeml
79
78
  env.email = optional_content(env_node, 'x:email', 'email', "x:#{@@eeml_version[:href]}")
80
79
  env.icon = optional_content(env_node, 'x:icon', 'icon', "x:#{@@eeml_version[:href]}")
81
80
  env.private = (optional_content(env_node, 'x:private', 'private', "x:#{@@eeml_version[:href]}") == "true")
82
-
83
- owner_node = env_node.find_first('x:owner', "x:#{@@eeml_version[:href]}")
84
- env.owner = extractOwner(owner_node) if owner_node
81
+ env.owner = optional_content(env_node, 'x:owner', 'owner', "x:#{@@eeml_version[:href]}")
85
82
 
86
83
  #find_first_node_or_fail(env_node, 'x:location', 'location')
87
84
  loc_node = env_node.find_first('x:location', "x:#{@@eeml_version[:href]}")
@@ -98,18 +95,6 @@ module Eeml
98
95
  return env
99
96
  end
100
97
 
101
- def extractOwner(node)
102
- #<owner>
103
- # <login>bob</login>
104
- # <url>http://pachube.com/users/bob</url>
105
- #</owner>
106
- raise "given nil node" if node.nil?
107
- owner = Owner.new
108
- owner.login = optional_content(node, 'x:login', 'login', "x:#{@eeml_version[:href]}")
109
- owner.url = optional_content(node, 'x:url', 'url', "x:#{@eeml_version[:href]}")
110
- return owner
111
- end
112
-
113
98
  def extractLocation(node)
114
99
  #<location domain="physical" exposure="outdoor" disposition="mobile">
115
100
  # <lat>50.1</lat>
data/lib/eeml.rb CHANGED
@@ -6,6 +6,7 @@ require 'blank'
6
6
  require 'libxml'
7
7
  require 'yajl/json_gem'
8
8
  require 'lightcsv'
9
+ require 'eeml/attr_alias'
9
10
  require 'eeml/constants'
10
11
  require 'eeml/exceptions'
11
12
  require 'eeml/helpers'
@@ -16,9 +17,6 @@ require 'time'
16
17
  module Eeml
17
18
 
18
19
  # library version number
19
- VERSION = '0.0.35'
20
-
21
- # TODO: put in some configuration file, not here
22
- LOCAL_EEML_SCHEMA_LOCATION = 'schemas/eeml/005.xsd'
20
+ VERSION = '0.0.36'
23
21
 
24
22
  end #module
@@ -38,4 +38,6 @@
38
38
  "id":"1247",
39
39
  "title":"title here",
40
40
  "private":"false",
41
+ "publisher":"http://www.pachube.com",
42
+ "owner":"http://www.pachube.com/users/joe",
41
43
  "version":"1.0.0"}
@@ -0,0 +1,40 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <eeml xmlns="http://www.eeml.org/xsd/0.5.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="0.5.2" xsi:schemaLocation="http://www.eeml.org/xsd/0.5.2 http://www.eeml.org/xsd/0.5.2/0.5.2.xsd">
3
+ <environment updated="2010-09-23T09:54:57.873029Z" publisher="http://www.pachube.com">
4
+ <title>title here</title>
5
+ <feed>http://appdev.loc:3000/api/feeds/.xml</feed>
6
+ <status>live</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
+ <private>false</private>
12
+ <owner>http://www.pachube.com/users/joe</owner>
13
+ <location domain="physical" exposure="outdoor" disposition="mobile">
14
+ <name>Up on the roof (somewhere)</name>
15
+ <lat>50.1</lat>
16
+ <lon>48.7</lon>
17
+ <ele>1.34</ele>
18
+ </location>
19
+ <data id="0">
20
+ <tag>tagD0</tag>
21
+ <current_value at="2010-09-23T09:54:57.873029Z">0</current_value>
22
+ <max_value>1022.0</max_value>
23
+ <min_value>-9999.0</min_value>
24
+ <unit type="basicSI" symbol="C">Celsius</unit>
25
+ </data>
26
+ <data id="1">
27
+ <current_value at="2010-09-23T09:54:57.873029Z">33</current_value>
28
+ <max_value>1023.0</max_value>
29
+ <min_value>0.0</min_value>
30
+ </data>
31
+ <data id="2">
32
+ <tag>tagD2a</tag>
33
+ <tag>tagD2b</tag>
34
+ <tag>tagD2c</tag>
35
+ <current_value at="2010-09-23T09:54:57.873029Z">42.1</current_value>
36
+ <max_value>1021.0</max_value>
37
+ <min_value>23.4</min_value>
38
+ </data>
39
+ </environment>
40
+ </eeml>
@@ -38,4 +38,6 @@
38
38
  "id":"1247",
39
39
  "title":"title here",
40
40
  "version":"1.0.0",
41
+ "owner":"http:\/\/www.pachube.com\/users\/joe",
42
+ "publisher":"http:\/\/www.pachube.com",
41
43
  "tags":["tagE0", "tagE1"]}
@@ -36,13 +36,24 @@ class TestEnvironment < Test::Unit::TestCase
36
36
  assert_equal('http://example.com/creator/', env.creator)
37
37
  end
38
38
 
39
- test "creating Env object from some 0.5.2 eeml" do
39
+ test "creating minimal Env object from some 0.5.2 eeml" do
40
40
  env = create_env_from_eeml_052
41
41
 
42
42
  # simple text nodes available
43
43
  assert_equal("Pachube Office environment", env.title)
44
44
  end
45
45
 
46
+ test "creating complete Env object from some 0.5.2 eeml" do
47
+ env = create_complete_env_from_eeml_052
48
+
49
+ # simple text nodes available
50
+ assert_equal("title here", env.title)
51
+
52
+ # new attributes
53
+ assert_equal("http://www.pachube.com", env.publisher)
54
+ assert_equal("http://www.pachube.com/users/joe", env.owner)
55
+ end
56
+
46
57
  test 'location parses ok' do
47
58
  env = create_env_from_xml_file_one
48
59
 
@@ -344,6 +355,7 @@ class TestEnvironment < Test::Unit::TestCase
344
355
  #env attrs
345
356
  assert_equal('1247', env.identifier)
346
357
  assert_equal('2009-02-11T10:56:56Z', env.updated.utc.iso8601)
358
+
347
359
  end
348
360
 
349
361
  test "location parses ok from json" do
@@ -427,6 +439,10 @@ class TestEnvironment < Test::Unit::TestCase
427
439
  #env attrs
428
440
  assert_equal('1247', env.identifier)
429
441
  assert_equal('2010-02-11T10:56:56Z', env.updated.utc.iso8601)
442
+
443
+ # new stuff
444
+ assert_equal("http://www.pachube.com", env.publisher)
445
+ assert_equal("http://www.pachube.com/users/joe", env.owner)
430
446
  end
431
447
 
432
448
  test "location parses ok from json when parsing a v1.0.0 file" do
@@ -775,4 +791,8 @@ CSV
775
791
  def create_env_from_eeml_052
776
792
  return create_env_from_xml_file("environment_minimal_052.xml")
777
793
  end
794
+
795
+ def create_complete_env_from_eeml_052
796
+ return create_env_from_xml_file("eeml_datastream_052.xml")
797
+ end
778
798
  end
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: 89
4
+ hash: 87
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 35
10
- version: 0.0.35
9
+ - 36
10
+ version: 0.0.36
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-02-24 00:00:00 +00:00
21
+ date: 2011-02-28 00:00:00 +00:00
22
22
  default_executable:
23
23
  dependencies:
24
24
  - !ruby/object:Gem::Dependency
@@ -89,6 +89,7 @@ files:
89
89
  - example.rb
90
90
  - lib/blank.rb
91
91
  - lib/eeml.rb
92
+ - lib/eeml/attr_alias.rb
92
93
  - lib/eeml/constants.rb
93
94
  - lib/eeml/csv_parser_v1.rb
94
95
  - lib/eeml/csv_parser_v2.rb
@@ -121,6 +122,7 @@ files:
121
122
  - test/data/doc_2.xml
122
123
  - test/data/doc_2_expected.json
123
124
  - test/data/eeml_datastream_051.xml
125
+ - test/data/eeml_datastream_052.xml
124
126
  - test/data/environment_minimal_051.xml
125
127
  - test/data/environment_minimal_052.xml
126
128
  - test/data/environment_tags.json