Floppy-eeml 0.0.1
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/COPYING +19 -0
- data/README +29 -0
- data/lib/eeml.rb +3 -0
- data/lib/eeml/data.rb +17 -0
- data/lib/eeml/environment.rb +68 -0
- data/lib/eeml/exceptions.rb +7 -0
- metadata +58 -0
data/COPYING
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2008 James Smith (james@floppy.org.uk)
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
== EEML-Ruby
|
2
|
+
|
3
|
+
A Ruby wrapper around the Extended Environments Markup Language
|
4
|
+
(http://www.eeml.org)
|
5
|
+
|
6
|
+
Licensed under the MIT license (See COPYING file for details)
|
7
|
+
|
8
|
+
Author: James Smith (james@floppy.org.uk / http://www.floppy.org.uk)
|
9
|
+
|
10
|
+
Homepage: http://github.com/Floppy/eeml-ruby
|
11
|
+
|
12
|
+
== INSTALLATION
|
13
|
+
|
14
|
+
1) Enable gems from github, if you haven't already done so (rubygems >= 1.2):
|
15
|
+
> sudo gem sources -a http://gems.github.com
|
16
|
+
|
17
|
+
2) Install gem
|
18
|
+
> sudo gem install Floppy-eeml
|
19
|
+
|
20
|
+
== STATUS
|
21
|
+
|
22
|
+
The code can current create and parse EEML at a level equivalent to the
|
23
|
+
"minimal" EEML example at http://eeml.org/xml/005/minimal.xml.
|
24
|
+
|
25
|
+
To parse EEML: call EEML::Environment#from_eeml(your_eeml_string), and you will
|
26
|
+
get back an EEML::Environment object containing a number of EEML::Data objects.
|
27
|
+
|
28
|
+
To create EEML: create an EEML::Environment object, add one or more EEML::Data
|
29
|
+
objects to it, and call EEML::Environment#to_eeml.
|
data/lib/eeml.rb
ADDED
data/lib/eeml/data.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
module EEML
|
2
|
+
|
3
|
+
# An EEML data item. A valid EEML::Environment must contain at least one of
|
4
|
+
# these.
|
5
|
+
class Data
|
6
|
+
|
7
|
+
# Create a new EEML::Data item.
|
8
|
+
def initialize(value)
|
9
|
+
@value = value
|
10
|
+
end
|
11
|
+
|
12
|
+
# Data value
|
13
|
+
attr_accessor :value
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'builder'
|
3
|
+
require 'rexml/document'
|
4
|
+
|
5
|
+
module EEML
|
6
|
+
|
7
|
+
# An EEML environment object. Can contain a number of EEML::Data objects, as
|
8
|
+
# well as having other attributes.
|
9
|
+
class Environment
|
10
|
+
|
11
|
+
# Create new Environment object
|
12
|
+
def initialize
|
13
|
+
@data_items = []
|
14
|
+
end
|
15
|
+
|
16
|
+
# Create from an EEML document
|
17
|
+
def self.from_eeml(eeml)
|
18
|
+
# Parse EEML
|
19
|
+
doc = REXML::Document.new(eeml)
|
20
|
+
# Create environment object
|
21
|
+
env = Environment.new
|
22
|
+
# Read data items
|
23
|
+
REXML::XPath.each(doc, "/eeml/environment/data") do |node|
|
24
|
+
env << EEML::Data.new(node.elements['value'].text.to_f)
|
25
|
+
end
|
26
|
+
# Done
|
27
|
+
return env
|
28
|
+
end
|
29
|
+
|
30
|
+
# Convert to EEML
|
31
|
+
def to_eeml
|
32
|
+
# Check that we have some data items
|
33
|
+
raise EEML::NoData.new('EEML requires at least one data item') if size < 1
|
34
|
+
# Create EEML
|
35
|
+
eeml = Builder::XmlMarkup.new
|
36
|
+
eeml.instruct!
|
37
|
+
eeml.eeml(:xmlns => "http://www.eeml.org/xsd/005",
|
38
|
+
:'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance",
|
39
|
+
:'xsi:schemaLocation' => "http://www.eeml.org/xsd/005 http://www.eeml.org/xsd/005/005.xsd") do
|
40
|
+
eeml.environment do
|
41
|
+
@data_items.each_index do |i|
|
42
|
+
eeml.data(:id => i) do
|
43
|
+
eeml.value @data_items[i].value
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Add an EEML::Data object to the environment
|
51
|
+
def <<(value)
|
52
|
+
raise TypeError.new('Only EEML::Data objects can be added to EEML::Environment objects') unless value.is_a?(EEML::Data)
|
53
|
+
@data_items << value
|
54
|
+
end
|
55
|
+
|
56
|
+
# The number of EEML::Data objects in the environment
|
57
|
+
def size
|
58
|
+
@data_items.size
|
59
|
+
end
|
60
|
+
|
61
|
+
# Access contained EEML::Data objects
|
62
|
+
def [](index)
|
63
|
+
@data_items[index]
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: Floppy-eeml
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Smith
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-08-22 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: james@floppy.org.uk
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- README
|
26
|
+
- COPYING
|
27
|
+
- lib/eeml.rb
|
28
|
+
- lib/eeml/environment.rb
|
29
|
+
- lib/eeml/data.rb
|
30
|
+
- lib/eeml/exceptions.rb
|
31
|
+
has_rdoc: true
|
32
|
+
homepage: http://github.com/Floppy/eeml-ruby
|
33
|
+
post_install_message:
|
34
|
+
rdoc_options: []
|
35
|
+
|
36
|
+
require_paths:
|
37
|
+
- lib
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: "0"
|
43
|
+
version:
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: "0"
|
49
|
+
version:
|
50
|
+
requirements: []
|
51
|
+
|
52
|
+
rubyforge_project:
|
53
|
+
rubygems_version: 1.2.0
|
54
|
+
signing_key:
|
55
|
+
specification_version: 2
|
56
|
+
summary: A Ruby wrapper around the Extended Environments Markup Language
|
57
|
+
test_files: []
|
58
|
+
|