taverna-baclava 1.0.0

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/Changes.rdoc ADDED
@@ -0,0 +1,8 @@
1
+ = Changes log for the Taverna Baclava Ruby Gem
2
+
3
+
4
+ == About this Changes file
5
+
6
+ This file is, at least in part, generated by the following command:
7
+
8
+ $ git log --pretty=format:"* %s" --reverse --no-merges <commit-hash>..
data/Licence.rdoc ADDED
@@ -0,0 +1,29 @@
1
+ Copyright (c) 2006-2012 The University of Manchester, UK.
2
+
3
+ All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ * Redistributions of source code must retain the above copyright notice,
9
+ this list of conditions and the following disclaimer.
10
+
11
+ * Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ * Neither the names of The University of Manchester nor the names of its
16
+ contributors may be used to endorse or promote products derived from this
17
+ software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
+ POSSIBILITY OF SUCH DAMAGE.
data/ReadMe.rdoc ADDED
@@ -0,0 +1,17 @@
1
+ = Taverna[http://www.taverna.org.uk/] Baclava Gem
2
+
3
+ Authors:: Robert Haines, Stian Soiland-Reyes, David Withers, Emmanuel Tagarira
4
+ Contact:: mailto:support@mygrid.org.uk
5
+ URL:: http://www.taverna.org.uk/
6
+ Licence:: BSD (See Licence or http://www.opensource.org/licenses/bsd-license.php)
7
+ Copyright:: (c) 2006-2012 The University of Manchester, UK
8
+
9
+ == Synopsis
10
+
11
+ This is a Ruby library to support the reading and writing of the
12
+ Baclava data format.
13
+
14
+ == Support
15
+
16
+ Please email mailto:support@mygrid.org.uk for any questions relating to
17
+ this Ruby gem.
@@ -0,0 +1,102 @@
1
+ # Copyright (c) 2006-2012 The University of Manchester, UK.
2
+ #
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # * Redistributions of source code must retain the above copyright notice,
9
+ # this list of conditions and the following disclaimer.
10
+ #
11
+ # * Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # * Neither the names of The University of Manchester nor the names of its
16
+ # contributors may be used to endorse or promote products derived from this
17
+ # software without specific prior written permission.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
+ # POSSIBILITY OF SUCH DAMAGE.
30
+ #
31
+ # Authors: Robert Haines, Stian Soiland-Reyes, David Withers, Emmanuel Tagarira
32
+
33
+ module Taverna
34
+ module Baclava
35
+
36
+ # An annotated data value.
37
+ class Node
38
+
39
+ # The value of this Node.
40
+ attr_reader :value
41
+
42
+ # A list of annotations on this Node.
43
+ attr_accessor :annotation
44
+
45
+ # The syntactic type of this node.
46
+ attr_reader :syntactic_type
47
+
48
+ # Create a new Node. If a list is passed in as the value then it is
49
+ # recursively processed into a list of Nodes.
50
+ def initialize(value = nil, annotation = [])
51
+ @syntactic_type = ""
52
+ @value = value.nil? ? nil : _set_value(value)
53
+ @annotation = annotation
54
+ end
55
+
56
+ # Set the value of this Node. If a list is passed in then it is
57
+ # recursively processed into a list of Nodes.
58
+ def value=(value)
59
+ @value = value.nil? ? nil : _set_value(value)
60
+ end
61
+
62
+ # Test for equality between this and another Node.
63
+ def ==(other)
64
+ @value == other.value and @annotation == other.annotation
65
+ end
66
+
67
+ # Extract the data value(s) from this Node and return them in the same
68
+ # structure as the given Node.
69
+ def Node.extract_node_data(node)
70
+ case node
71
+ when Hash
72
+ hash = {}
73
+ node.each { |k, v| hash[k] = Node.extract_node_data(v.value) }
74
+ hash
75
+ when Array
76
+ list = []
77
+ node.each { |n| list << Node.extract_node_data(n.value) }
78
+ list
79
+ when Taverna::Baclava::Node
80
+ Node.extract_node_data(node.value)
81
+ else
82
+ node
83
+ end
84
+ end
85
+
86
+ private
87
+
88
+ # Recursively set the value of this node, creating the underlying lists
89
+ # if necessary.
90
+ def _set_value(value)
91
+ if value.is_a? Array
92
+ value.map do |v|
93
+ v.is_a?(Taverna::Baclava::Node) ? v : Node.new(v)
94
+ end
95
+ else
96
+ value.to_s
97
+ end
98
+ end
99
+
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,110 @@
1
+ # Copyright (c) 2006-2012 The University of Manchester, UK.
2
+ #
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # * Redistributions of source code must retain the above copyright notice,
9
+ # this list of conditions and the following disclaimer.
10
+ #
11
+ # * Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # * Neither the names of The University of Manchester nor the names of its
16
+ # contributors may be used to endorse or promote products derived from this
17
+ # software without specific prior written permission.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
+ # POSSIBILITY OF SUCH DAMAGE.
30
+ #
31
+ # Authors: Robert Haines, Stian Soiland-Reyes, David Withers, Emmanuel Tagarira
32
+
33
+ require 'baclava/node'
34
+ require 'rexml/document'
35
+
36
+ module Taverna
37
+ module Baclava
38
+
39
+ class Reader
40
+
41
+ # Reads a baclava document and returns a hash of Baclava::Node objects.
42
+ def self.read(xml)
43
+ if xml.kind_of?(REXML::Document)
44
+ document = xml
45
+ else
46
+ document = REXML::Document.new(xml)
47
+ end
48
+ root = document.root
49
+ raise "'#{root.name}' doesn't appear to be a data thing!" if root.name != "dataThingMap"
50
+
51
+ create_data_map(root)
52
+ end
53
+
54
+ # :stopdoc:
55
+
56
+ def self.create_data_map(element)
57
+ data_map = {}
58
+
59
+ element.each_element('b:dataThing') do |datathing|
60
+ key = datathing.attribute('key').value
61
+ data = Node.new
62
+ data_map[key] = data
63
+ datathing.each_element('b:myGridDataDocument') do |dataDocument|
64
+ dataDocument.each_element('s:metadata') do |metadata|
65
+ data.annotation = get_metadata(metadata)
66
+ end
67
+ dataDocument.each_element('b:partialOrder') do |partialOrder|
68
+ data.value = get_list(partialOrder)
69
+ end
70
+ dataDocument.each_element('b:dataElement') do |dataElement|
71
+ data.value = get_element(dataElement)
72
+ end
73
+ end
74
+ end
75
+
76
+ data_map
77
+ end
78
+
79
+ def self.get_list(element)
80
+ list = []
81
+ element.each_element('b:itemList') do |itemList|
82
+ itemList.each_element('b:dataElement') do |dataElement|
83
+ list << get_element(dataElement)
84
+ end
85
+ itemList.each_element('b:partialOrder') do |partialOrder|
86
+ list << get_list(partialOrder)
87
+ end
88
+ end
89
+ list
90
+ end
91
+
92
+ def self.get_metadata(element)
93
+ list = []
94
+ element.each_element('s:mimeTypes') do |mimeTypes|
95
+ mimeTypes.each_element('s:mimeType') do |mimeType|
96
+ list << mimeType.text
97
+ end
98
+ end
99
+ list
100
+ end
101
+
102
+ def self.get_element(element)
103
+ element.each_element('b:dataElementData') do |data|
104
+ text = data.text
105
+ return text.nil? ? "" : Base64.decode64(text)
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,122 @@
1
+ # Copyright (c) 2006-2012 The University of Manchester, UK.
2
+ #
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # * Redistributions of source code must retain the above copyright notice,
9
+ # this list of conditions and the following disclaimer.
10
+ #
11
+ # * Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # * Neither the names of The University of Manchester nor the names of its
16
+ # contributors may be used to endorse or promote products derived from this
17
+ # software without specific prior written permission.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
+ # POSSIBILITY OF SUCH DAMAGE.
30
+ #
31
+ # Authors: Robert Haines, Stian Soiland-Reyes, David Withers, Emmanuel Tagarira
32
+
33
+
34
+ require 'baclava/node'
35
+ require 'base64'
36
+ require 'rexml/document'
37
+ require 'rubygems'
38
+ require 'builder'
39
+
40
+ module Taverna
41
+ module Baclava
42
+
43
+ class Writer
44
+
45
+ # Write a hash of Baclava::Node objects into a REXML::Document.
46
+ def self.write_doc(data_map)
47
+ REXML::Document.new(write(data_map))
48
+ end
49
+
50
+ # Write a hash of Baclava::Node objects into a XML String.
51
+ def self.write(data_map)
52
+ xml = Builder::XmlMarkup.new :indent => 2
53
+ xml.instruct!
54
+ xml.b :dataThingMap, 'xmlns:b' => 'http://org.embl.ebi.escience/baclava/0.1alpha' do
55
+ data_map.each_key do |key|
56
+ data = data_map[key]
57
+ xml.b :dataThing, 'key' => key do
58
+ xml.b :myGridDataDocument, 'lsid' => '', 'syntactictype' => data.syntactic_type do
59
+ write_metadata xml, data.annotation unless data.annotation.nil?
60
+ write_data xml, data.value
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+
67
+ # :stopdoc:
68
+
69
+ def self.write_metadata(xml, metadata)
70
+ xml.s :metadata, 'xmlns:s' => 'http://org.embl.ebi.escience/xscufl/0.1alpha' do
71
+ return if metadata.empty?
72
+ xml.s :mimeTypes do
73
+ metadata.each do |mimetype|
74
+ xml.s :mimetype, mimetype.chomp
75
+ end
76
+ end
77
+ end
78
+ end
79
+
80
+ def self.write_data(xml, data, index = nil)
81
+ if data.is_a? Array
82
+ write_list xml, data, index
83
+ else
84
+ if index
85
+ xml.b :dataElement, 'lsid' => '', 'index' => index do |x|
86
+ x.b :dataElementData, Base64.encode64(data).chomp
87
+ end
88
+ else
89
+ xml.b :dataElement, 'lsid' => '' do |x|
90
+ x.b :dataElementData, Base64.encode64(data).chomp
91
+ end
92
+ end
93
+ end
94
+ end
95
+
96
+ def self.write_list(xml, list, index)
97
+ if index
98
+ xml.b :partialOrder, 'lsid' => '', 'type' => 'list', 'index' => index do
99
+ write_item_list xml, list
100
+ end
101
+ else
102
+ xml.b :partialOrder, 'lsid' => '', 'type' => 'list' do
103
+ write_item_list xml, list
104
+ end
105
+ end
106
+ end
107
+
108
+ def self.write_item_list(xml, list)
109
+ xml.b :relationList do
110
+ (1...list.length).each do |i|
111
+ xml.b :relation, 'parent' => (i - 1), 'child' => i
112
+ end
113
+ end
114
+ xml.b :itemList do
115
+ (0...list.length).each do |i|
116
+ write_data xml, list[i].value, i
117
+ end
118
+ end
119
+ end
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,34 @@
1
+ # Copyright (c) 2006-2012 The University of Manchester, UK.
2
+ #
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # * Redistributions of source code must retain the above copyright notice,
9
+ # this list of conditions and the following disclaimer.
10
+ #
11
+ # * Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # * Neither the names of The University of Manchester nor the names of its
16
+ # contributors may be used to endorse or promote products derived from this
17
+ # software without specific prior written permission.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
+ # POSSIBILITY OF SUCH DAMAGE.
30
+ #
31
+ # Authors: Robert Haines, Stian Soiland-Reyes, David Withers, Emmanuel Tagarira
32
+
33
+ require 'baclava/reader'
34
+ require 'baclava/writer'
@@ -0,0 +1,56 @@
1
+ # Copyright (c) 2006-2012 The University of Manchester, UK.
2
+ #
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # * Redistributions of source code must retain the above copyright notice,
9
+ # this list of conditions and the following disclaimer.
10
+ #
11
+ # * Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # * Neither the names of The University of Manchester nor the names of its
16
+ # contributors may be used to endorse or promote products derived from this
17
+ # software without specific prior written permission.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
+ # POSSIBILITY OF SUCH DAMAGE.
30
+ #
31
+ # Author: Robert Haines
32
+
33
+ class TestBaclava < Test::Unit::TestCase
34
+ SINGLE_IN = []
35
+ MANY_IN = [[["boo"]], [["", "Hello"]], [], [[], ["test"], []]]
36
+ MAP = {
37
+ "SINGLE_IN" => Taverna::Baclava::Node.new(SINGLE_IN),
38
+ "MANY_IN" => Taverna::Baclava::Node.new(MANY_IN)
39
+ }
40
+
41
+ def test_reader
42
+ input = Taverna::Baclava::Reader.read(File.read("test/test.baclava"))
43
+ assert_equal(input, MAP)
44
+ map = Taverna::Baclava::Node.extract_node_data(input)
45
+ assert_equal(map["SINGLE_IN"], SINGLE_IN)
46
+ assert_equal(map["MANY_IN"], MANY_IN)
47
+ end
48
+
49
+ def test_writer
50
+ input = Taverna::Baclava::Reader.read(Taverna::Baclava::Writer.write(MAP))
51
+ assert_equal(input, MAP)
52
+ map = Taverna::Baclava::Node.extract_node_data(input)
53
+ assert_equal(map["SINGLE_IN"], SINGLE_IN)
54
+ assert_equal(map["MANY_IN"], MANY_IN)
55
+ end
56
+ end
data/test/tc_node.rb ADDED
@@ -0,0 +1,75 @@
1
+ # Copyright (c) 2006-2012 The University of Manchester, UK.
2
+ #
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # * Redistributions of source code must retain the above copyright notice,
9
+ # this list of conditions and the following disclaimer.
10
+ #
11
+ # * Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # * Neither the names of The University of Manchester nor the names of its
16
+ # contributors may be used to endorse or promote products derived from this
17
+ # software without specific prior written permission.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
+ # POSSIBILITY OF SUCH DAMAGE.
30
+ #
31
+ # Author: Robert Haines
32
+
33
+ class TestNode < Test::Unit::TestCase
34
+ TEST_VALUE = "Hello"
35
+ TEST_LIST = ["Hello", "World!"]
36
+ TEST_NUMBER = 1337
37
+
38
+ def test_singleton
39
+ node = Taverna::Baclava::Node.new(TEST_VALUE)
40
+ assert_equal(node.value, TEST_VALUE)
41
+ assert_equal(node.annotation, [])
42
+ end
43
+
44
+ def test_lists
45
+ node = Taverna::Baclava::Node.new(TEST_LIST)
46
+ assert_equal(node.value[0].value, TEST_LIST[0])
47
+ assert_equal(node.value[1].value, TEST_LIST[1])
48
+ assert_equal(node.annotation, [])
49
+ end
50
+
51
+ def test_non_strings
52
+ node = Taverna::Baclava::Node.new(TEST_NUMBER)
53
+ assert_equal(node.value, TEST_NUMBER.to_s)
54
+ assert_equal(node.annotation, [])
55
+ end
56
+
57
+ def test_extract
58
+ n1 = Taverna::Baclava::Node.new(TEST_VALUE)
59
+ n2 = Taverna::Baclava::Node.new(TEST_LIST)
60
+ n3 = Taverna::Baclava::Node.new(TEST_NUMBER)
61
+ map = {
62
+ "value" => n1,
63
+ "list" => n2,
64
+ "number" => n3
65
+ }
66
+
67
+ assert_equal(Taverna::Baclava::Node.extract_node_data(n1), TEST_VALUE)
68
+ assert_equal(Taverna::Baclava::Node.extract_node_data(n2), TEST_LIST)
69
+ assert_equal(Taverna::Baclava::Node.extract_node_data(n3),
70
+ TEST_NUMBER.to_s)
71
+
72
+ map_x = Taverna::Baclava::Node.extract_node_data(map)
73
+ assert_equal(map_x["list"], TEST_LIST)
74
+ end
75
+ end
data/test/test.baclava ADDED
@@ -0,0 +1,86 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <b:dataThingMap xmlns:b="http://org.embl.ebi.escience/baclava/0.1alpha">
3
+ <b:dataThing key="MANY_IN">
4
+ <b:myGridDataDocument lsid="" syntactictype="l(l(l('null')))">
5
+ <s:metadata xmlns:s="http://org.embl.ebi.escience/xscufl/0.1alpha" />
6
+ <b:partialOrder lsid="" type="list">
7
+ <b:relationList>
8
+ <b:relation parent="0" child="1" />
9
+ <b:relation parent="1" child="2" />
10
+ <b:relation parent="2" child="3" />
11
+ </b:relationList>
12
+ <b:itemList>
13
+ <b:partialOrder lsid="" type="list" index="0">
14
+ <b:relationList />
15
+ <b:itemList>
16
+ <b:partialOrder lsid="" type="list" index="0">
17
+ <b:relationList />
18
+ <b:itemList>
19
+ <b:dataElement lsid="" index="0">
20
+ <b:dataElementData>Ym9v</b:dataElementData>
21
+ </b:dataElement>
22
+ </b:itemList>
23
+ </b:partialOrder>
24
+ </b:itemList>
25
+ </b:partialOrder>
26
+ <b:partialOrder lsid="" type="list" index="1">
27
+ <b:relationList />
28
+ <b:itemList>
29
+ <b:partialOrder lsid="" type="list" index="0">
30
+ <b:relationList>
31
+ <b:relation parent="0" child="1" />
32
+ </b:relationList>
33
+ <b:itemList>
34
+ <b:dataElement lsid="" index="0">
35
+ <b:dataElementData />
36
+ </b:dataElement>
37
+ <b:dataElement lsid="" index="1">
38
+ <b:dataElementData>SGVsbG8=</b:dataElementData>
39
+ </b:dataElement>
40
+ </b:itemList>
41
+ </b:partialOrder>
42
+ </b:itemList>
43
+ </b:partialOrder>
44
+ <b:partialOrder lsid="" type="list" index="2">
45
+ <b:relationList />
46
+ <b:itemList />
47
+ </b:partialOrder>
48
+ <b:partialOrder lsid="" type="list" index="3">
49
+ <b:relationList>
50
+ <b:relation parent="0" child="1" />
51
+ <b:relation parent="1" child="2" />
52
+ </b:relationList>
53
+ <b:itemList>
54
+ <b:partialOrder lsid="" type="list" index="0">
55
+ <b:relationList />
56
+ <b:itemList />
57
+ </b:partialOrder>
58
+ <b:partialOrder lsid="" type="list" index="1">
59
+ <b:relationList />
60
+ <b:itemList>
61
+ <b:dataElement lsid="" index="0">
62
+ <b:dataElementData>dGVzdA==</b:dataElementData>
63
+ </b:dataElement>
64
+ </b:itemList>
65
+ </b:partialOrder>
66
+ <b:partialOrder lsid="" type="list" index="2">
67
+ <b:relationList />
68
+ <b:itemList />
69
+ </b:partialOrder>
70
+ </b:itemList>
71
+ </b:partialOrder>
72
+ </b:itemList>
73
+ </b:partialOrder>
74
+ </b:myGridDataDocument>
75
+ </b:dataThing>
76
+ <b:dataThing key="SINGLE_IN">
77
+ <b:myGridDataDocument lsid="" syntactictype="l('null')">
78
+ <s:metadata xmlns:s="http://org.embl.ebi.escience/xscufl/0.1alpha" />
79
+ <b:partialOrder lsid="" type="list">
80
+ <b:relationList />
81
+ <b:itemList />
82
+ </b:partialOrder>
83
+ </b:myGridDataDocument>
84
+ </b:dataThing>
85
+ </b:dataThingMap>
86
+
@@ -0,0 +1,38 @@
1
+ # Copyright (c) 2006-2012 The University of Manchester, UK.
2
+ #
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # * Redistributions of source code must retain the above copyright notice,
9
+ # this list of conditions and the following disclaimer.
10
+ #
11
+ # * Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # * Neither the names of The University of Manchester nor the names of its
16
+ # contributors may be used to endorse or promote products derived from this
17
+ # software without specific prior written permission.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
+ # POSSIBILITY OF SUCH DAMAGE.
30
+ #
31
+ # Author: Robert Haines
32
+
33
+ require 'test/unit'
34
+ require 'taverna-baclava'
35
+
36
+ # tests
37
+ require 'tc_node'
38
+ require 'tc_baclava'
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: taverna-baclava
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Robert Haines
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-03-13 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rake
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 63
29
+ segments:
30
+ - 0
31
+ - 9
32
+ - 2
33
+ version: 0.9.2
34
+ type: :development
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: rdoc
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 43
45
+ segments:
46
+ - 3
47
+ - 9
48
+ - 4
49
+ version: 3.9.4
50
+ type: :development
51
+ version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ name: builder
54
+ prerelease: false
55
+ requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ hash: 7
61
+ segments:
62
+ - 3
63
+ - 0
64
+ - 0
65
+ version: 3.0.0
66
+ type: :runtime
67
+ version_requirements: *id003
68
+ description: A Ruby library to support the reading and writing of the Baclava data format.
69
+ email: rhaines@manchester.ac.uk
70
+ executables: []
71
+
72
+ extensions: []
73
+
74
+ extra_rdoc_files:
75
+ - ReadMe.rdoc
76
+ - Licence.rdoc
77
+ - Changes.rdoc
78
+ files:
79
+ - lib/baclava/node.rb
80
+ - lib/baclava/writer.rb
81
+ - lib/baclava/reader.rb
82
+ - lib/taverna-baclava.rb
83
+ - test/tc_baclava.rb
84
+ - test/ts_baclava.rb
85
+ - test/tc_node.rb
86
+ - test/test.baclava
87
+ - ReadMe.rdoc
88
+ - Licence.rdoc
89
+ - Changes.rdoc
90
+ homepage: http://www.taverna.org.uk/
91
+ licenses: []
92
+
93
+ post_install_message:
94
+ rdoc_options:
95
+ - -N
96
+ - --tab-width=2
97
+ - --main=ReadMe.rdoc
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ hash: 3
106
+ segments:
107
+ - 0
108
+ version: "0"
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ hash: 3
115
+ segments:
116
+ - 0
117
+ version: "0"
118
+ requirements: []
119
+
120
+ rubyforge_project:
121
+ rubygems_version: 1.8.10
122
+ signing_key:
123
+ specification_version: 3
124
+ summary: Ruby support for the Baclava file format.
125
+ test_files:
126
+ - test/ts_baclava.rb