Class: Taverna::Baclava::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/baclava/node.rb

Overview

An annotated data value.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value = nil, annotation = []) ⇒ Node

Create a new Node. If a list is passed in as the value then it is recursively processed into a list of Nodes.



50
51
52
53
54
# File 'lib/baclava/node.rb', line 50

def initialize(value = nil, annotation = [])
  @syntactic_type = ""
  @value = value.nil? ? nil : _set_value(value)
  @annotation = annotation
end

Instance Attribute Details

#annotationObject

A list of annotations on this Node.



43
44
45
# File 'lib/baclava/node.rb', line 43

def annotation
  @annotation
end

#syntactic_typeObject (readonly)

The syntactic type of this node.



46
47
48
# File 'lib/baclava/node.rb', line 46

def syntactic_type
  @syntactic_type
end

#valueObject

The value of this Node.



40
41
42
# File 'lib/baclava/node.rb', line 40

def value
  @value
end

Class Method Details

.extract_node_data(node) ⇒ Object

Extract the data value(s) from this Node and return them in the same structure as the given Node.



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/baclava/node.rb', line 69

def Node.extract_node_data(node)
  case node
  when Hash
    hash = {}
    node.each { |k, v| hash[k] = Node.extract_node_data(v.value) }
    hash
  when Array
    list = []
    node.each { |n| list << Node.extract_node_data(n.value) }
    list
  when Taverna::Baclava::Node
    Node.extract_node_data(node.value)
  else
    node
  end
end

Instance Method Details

#==(other) ⇒ Object

Test for equality between this and another Node.



63
64
65
# File 'lib/baclava/node.rb', line 63

def ==(other)
  @value == other.value and @annotation == other.annotation
end