Floppy-eeml 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +4 -3
- data/lib/eeml.rb +2 -0
- data/lib/eeml/data.rb +23 -0
- data/lib/eeml/environment.rb +120 -14
- data/lib/eeml/location.rb +94 -0
- data/lib/eeml/unit.rb +41 -0
- metadata +4 -2
data/README
CHANGED
@@ -19,8 +19,9 @@ Homepage: http://github.com/Floppy/eeml-ruby
|
|
19
19
|
|
20
20
|
== STATUS
|
21
21
|
|
22
|
-
The code can current create
|
23
|
-
"
|
22
|
+
The code can current create EEML at a level equivalent to the
|
23
|
+
"complete" EEML example at http://eeml.org/xml/005/complete.xml, and parse the
|
24
|
+
"minimal" level at http://eeml.org/xml/005/minimal.xml
|
24
25
|
|
25
26
|
To parse EEML: call EEML::Environment#from_eeml(your_eeml_string), and you will
|
26
27
|
get back an EEML::Environment object containing a number of EEML::Data objects.
|
@@ -32,4 +33,4 @@ objects to it, and call EEML::Environment#to_eeml.
|
|
32
33
|
|
33
34
|
The file examples/simple_server.rb contains a simple WEBrick server which serves
|
34
35
|
an EEML document. This allows a site like Pachube (http://www.pachube.com) to
|
35
|
-
|
36
|
+
fetch EEML data from your system.
|
data/lib/eeml.rb
CHANGED
data/lib/eeml/data.rb
CHANGED
@@ -7,11 +7,34 @@ module EEML
|
|
7
7
|
# Create a new EEML::Data item.
|
8
8
|
def initialize(value)
|
9
9
|
@value = value
|
10
|
+
@tags = []
|
10
11
|
end
|
11
12
|
|
12
13
|
# Data value
|
13
14
|
attr_accessor :value
|
14
15
|
|
16
|
+
# Tag array
|
17
|
+
attr_accessor :tags
|
18
|
+
|
19
|
+
# Minimum value
|
20
|
+
attr_accessor :min_value
|
21
|
+
|
22
|
+
# Maximum value
|
23
|
+
attr_accessor :max_value
|
24
|
+
|
25
|
+
# Unit of measurement
|
26
|
+
def unit
|
27
|
+
@unit
|
28
|
+
end
|
29
|
+
|
30
|
+
# Unit of measurement - must be a EEML::Unit object
|
31
|
+
def unit=(unit_val)
|
32
|
+
unless unit_val.is_a?(EEML::Unit)
|
33
|
+
raise TypeError.new("unit must be an EEML::Unit")
|
34
|
+
end
|
35
|
+
@unit = unit_val
|
36
|
+
end
|
37
|
+
|
15
38
|
end
|
16
39
|
|
17
40
|
end
|
data/lib/eeml/environment.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'builder'
|
3
3
|
require 'rexml/document'
|
4
|
+
require 'time'
|
4
5
|
|
5
6
|
module EEML
|
6
7
|
|
@@ -27,20 +28,62 @@ module EEML
|
|
27
28
|
return env
|
28
29
|
end
|
29
30
|
|
30
|
-
# Convert to EEML
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
eeml.
|
41
|
-
|
42
|
-
|
43
|
-
|
31
|
+
# Convert to EEML. Optional parameter describes the version of EEML to generate.
|
32
|
+
# Default (and currently only version implemented) is version 5.
|
33
|
+
def to_eeml(version = nil)
|
34
|
+
if version.nil? || version == 5
|
35
|
+
# Check that we have some data items
|
36
|
+
if size < 1
|
37
|
+
raise EEML::NoData.new('EEML requires at least one data item')
|
38
|
+
end
|
39
|
+
# Create EEML
|
40
|
+
eeml = Builder::XmlMarkup.new
|
41
|
+
eeml.instruct!
|
42
|
+
eeml_options = {:xmlns => "http://www.eeml.org/xsd/005",
|
43
|
+
:'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance",
|
44
|
+
:'xsi:schemaLocation' => "http://www.eeml.org/xsd/005 http://www.eeml.org/xsd/005/005.xsd"}
|
45
|
+
eeml_options[:version] = version if version
|
46
|
+
eeml.eeml(eeml_options) do
|
47
|
+
env_options = {}
|
48
|
+
env_options[:updated] = @updated_at.xmlschema if @updated_at
|
49
|
+
env_options[:creator] = @creator if @creator
|
50
|
+
env_options[:id] = @id if @id
|
51
|
+
eeml.environment(env_options) do |env|
|
52
|
+
env.title @title if @title
|
53
|
+
env.feed @feed if @feed
|
54
|
+
env.status @status.to_s if @status
|
55
|
+
env.description @description if @description
|
56
|
+
env.icon @icon if @icon
|
57
|
+
env.website @website if @website
|
58
|
+
env.email @email if @email
|
59
|
+
if @location
|
60
|
+
loc_options = {}
|
61
|
+
loc_options[:domain] = @location.domain
|
62
|
+
loc_options[:exposure] = @location.exposure if @location.exposure
|
63
|
+
loc_options[:disposition] = @location.disposition if @location.disposition
|
64
|
+
env.location(loc_options) do |loc|
|
65
|
+
loc.name @location.name if @location.name
|
66
|
+
loc.lat @location.lat if @location.lat
|
67
|
+
loc.lon @location.lon if @location.lon
|
68
|
+
loc.ele @location.ele if @location.ele
|
69
|
+
end
|
70
|
+
end
|
71
|
+
@data_items.each_index do |i|
|
72
|
+
env.data(:id => i) do |data|
|
73
|
+
@data_items[i].tags.each do |tag|
|
74
|
+
data.tag tag
|
75
|
+
end
|
76
|
+
value_options = {}
|
77
|
+
value_options[:maxValue] = @data_items[i].max_value if @data_items[i].max_value
|
78
|
+
value_options[:minValue] = @data_items[i].min_value if @data_items[i].min_value
|
79
|
+
data.value @data_items[i].value, value_options
|
80
|
+
if @data_items[i].unit
|
81
|
+
unit_options = {}
|
82
|
+
unit_options[:symbol] = @data_items[i].unit.symbol if @data_items[i].unit.symbol
|
83
|
+
unit_options[:type] = @data_items[i].unit.type if @data_items[i].unit.type
|
84
|
+
data.unit @data_items[i].unit.name, unit_options
|
85
|
+
end
|
86
|
+
end
|
44
87
|
end
|
45
88
|
end
|
46
89
|
end
|
@@ -63,6 +106,69 @@ module EEML
|
|
63
106
|
@data_items[index]
|
64
107
|
end
|
65
108
|
|
109
|
+
# The title for this EEML feed
|
110
|
+
attr_accessor :title
|
111
|
+
|
112
|
+
# The URL for this EEML feed
|
113
|
+
attr_accessor :feed
|
114
|
+
|
115
|
+
# The status of this EEML feed - can be :frozen or :live
|
116
|
+
def status
|
117
|
+
@status
|
118
|
+
end
|
119
|
+
# The status of this EEML feed - can be :frozen or :live
|
120
|
+
def status=(val)
|
121
|
+
unless [nil, :frozen, :live].include?(val)
|
122
|
+
raise ArgumentError.new("Status must be :frozen or :live")
|
123
|
+
end
|
124
|
+
@status = val
|
125
|
+
end
|
126
|
+
|
127
|
+
# A description of this EEML feed
|
128
|
+
attr_accessor :description
|
129
|
+
|
130
|
+
# The URL of an icon for this feed
|
131
|
+
attr_accessor :icon
|
132
|
+
|
133
|
+
# The URL of a website related to this feed
|
134
|
+
attr_accessor :website
|
135
|
+
|
136
|
+
# The email address of the feed creator
|
137
|
+
attr_accessor :email
|
138
|
+
|
139
|
+
# The location of the feed
|
140
|
+
attr_reader :location
|
141
|
+
|
142
|
+
# Set the location of the feed - loc must be an EEML::Location object
|
143
|
+
def location=(loc)
|
144
|
+
unless loc.is_a?(EEML::Location)
|
145
|
+
raise TypeError.new('loc must be an EEML::Location')
|
146
|
+
end
|
147
|
+
@location = loc
|
148
|
+
end
|
149
|
+
|
150
|
+
# Last updated time
|
151
|
+
attr_reader :updated_at
|
152
|
+
|
153
|
+
# Set last updated time
|
154
|
+
def updated_at=(time)
|
155
|
+
unless time.is_a?(Time)
|
156
|
+
raise TypeError.new('updated_at must be a Time object')
|
157
|
+
end
|
158
|
+
@updated_at = time
|
159
|
+
end
|
160
|
+
|
161
|
+
# Set last updated time
|
162
|
+
def set_updated!
|
163
|
+
@updated_at = Time.now
|
164
|
+
end
|
165
|
+
|
166
|
+
# A string showing the creator of this environment object
|
167
|
+
attr_accessor :creator
|
168
|
+
|
169
|
+
# The ID of the environment object
|
170
|
+
attr_accessor :id
|
171
|
+
|
66
172
|
end
|
67
173
|
|
68
174
|
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
module EEML
|
2
|
+
|
3
|
+
# An class representing a location. Can be added to EEML::Data objects.
|
4
|
+
class Location
|
5
|
+
|
6
|
+
# Create a new EEML::Location item. Domain setting is required, and must be either :physical or :virtual.
|
7
|
+
def initialize(loc_domain, options = {})
|
8
|
+
set_domain(loc_domain)
|
9
|
+
set_exposure(options[:exposure])
|
10
|
+
set_disposition(options[:disposition])
|
11
|
+
@name = options[:name]
|
12
|
+
self.lat = options[:lat]
|
13
|
+
self.lon = options[:lon]
|
14
|
+
@ele = options[:ele]
|
15
|
+
end
|
16
|
+
|
17
|
+
# Domain (:physical or :virtual)
|
18
|
+
attr_reader :domain
|
19
|
+
|
20
|
+
# Set the domain of the Location - must be either :physical or :virtual
|
21
|
+
def domain=(loc_domain)
|
22
|
+
set_domain(loc_domain)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Exposure (:indoor or :outdoor)
|
26
|
+
attr_reader :exposure
|
27
|
+
|
28
|
+
# Set the exposure of the Location - must be either :indoor or :outdoor
|
29
|
+
def exposure=(loc_exposure)
|
30
|
+
set_exposure(loc_exposure)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Disposition (:fixed or :mobile)
|
34
|
+
attr_reader :disposition
|
35
|
+
|
36
|
+
# Set the disposition of the Location - must be either :fixed or :mobile
|
37
|
+
def disposition=(loc_disposition)
|
38
|
+
set_disposition(loc_disposition)
|
39
|
+
end
|
40
|
+
|
41
|
+
# The name of the location
|
42
|
+
attr_accessor :name
|
43
|
+
|
44
|
+
# Latitude of location
|
45
|
+
attr_reader :lat
|
46
|
+
|
47
|
+
# Set the latitude of the location
|
48
|
+
def lat=(latitude)
|
49
|
+
if latitude && (latitude < -90 || latitude > 90)
|
50
|
+
raise ArgumentError.new("Latitude must be between -90 and +90")
|
51
|
+
end
|
52
|
+
@lat = latitude
|
53
|
+
end
|
54
|
+
|
55
|
+
# Longitude of location
|
56
|
+
attr_reader :lon
|
57
|
+
|
58
|
+
# Set the longitude of the location
|
59
|
+
def lon=(longitude)
|
60
|
+
if longitude && (longitude < -180 || longitude > 180)
|
61
|
+
raise ArgumentError.new("Longitude must be between -180 and +180")
|
62
|
+
end
|
63
|
+
@lon = longitude
|
64
|
+
end
|
65
|
+
|
66
|
+
# Elevation of location
|
67
|
+
attr_accessor :ele
|
68
|
+
|
69
|
+
protected
|
70
|
+
|
71
|
+
def set_domain(loc_domain)
|
72
|
+
unless [:physical, :virtual].include?(loc_domain)
|
73
|
+
raise ArgumentError.new("Domain must be :physical or :virtual")
|
74
|
+
end
|
75
|
+
@domain = loc_domain
|
76
|
+
end
|
77
|
+
|
78
|
+
def set_exposure(loc_exposure)
|
79
|
+
unless [nil, :indoor, :outdoor].include?(loc_exposure)
|
80
|
+
raise ArgumentError.new("Exposure must be :indoor or :outdoor")
|
81
|
+
end
|
82
|
+
@exposure = loc_exposure
|
83
|
+
end
|
84
|
+
|
85
|
+
def set_disposition(loc_disposition)
|
86
|
+
unless [nil, :fixed, :mobile].include?(loc_disposition)
|
87
|
+
raise ArgumentError.new("Disposition must be :fixed or :mobile")
|
88
|
+
end
|
89
|
+
@disposition = loc_disposition
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
data/lib/eeml/unit.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
module EEML
|
2
|
+
|
3
|
+
# An class representing a unit or measurement. Can be added to EEML::Data
|
4
|
+
# objects
|
5
|
+
class Unit
|
6
|
+
|
7
|
+
# Create a new EEML::Unit item.
|
8
|
+
def initialize(unit_name, options = {})
|
9
|
+
@name = unit_name
|
10
|
+
@symbol = options[:symbol]
|
11
|
+
set_type(options[:type])
|
12
|
+
end
|
13
|
+
|
14
|
+
# Name of the unit (e.g. "metre")
|
15
|
+
attr_accessor :name
|
16
|
+
|
17
|
+
# Symbol for the unit (e.g. "m")
|
18
|
+
attr_accessor :symbol
|
19
|
+
|
20
|
+
# Get the type of the unit
|
21
|
+
def type
|
22
|
+
@type
|
23
|
+
end
|
24
|
+
|
25
|
+
# Set the type of the unit - must be one of :basicSI, :derivedSI, :conversionBasedUnits, :derivedUnits or :contextDependentUnits
|
26
|
+
def type=(unit_type)
|
27
|
+
set_type(unit_type)
|
28
|
+
end
|
29
|
+
|
30
|
+
protected
|
31
|
+
|
32
|
+
def set_type(unit_type)
|
33
|
+
unless [nil, :basicSI, :derivedSI, :conversionBasedUnits, :derivedUnits, :contextDependentUnits].include?(unit_type)
|
34
|
+
raise ArgumentError.new("Type must be one of :basicSI, :derivedSI, :conversionBasedUnits, :derivedUnits or :contextDependentUnits")
|
35
|
+
end
|
36
|
+
@type = unit_type
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Floppy-eeml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Smith
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-08-
|
12
|
+
date: 2008-08-27 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -28,6 +28,8 @@ files:
|
|
28
28
|
- lib/eeml/environment.rb
|
29
29
|
- lib/eeml/data.rb
|
30
30
|
- lib/eeml/exceptions.rb
|
31
|
+
- lib/eeml/location.rb
|
32
|
+
- lib/eeml/unit.rb
|
31
33
|
- examples/simple_server.rb
|
32
34
|
has_rdoc: true
|
33
35
|
homepage: http://github.com/Floppy/eeml-ruby
|