Class: XMLBuilder::PathParser::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/ec2/amitools/xmlbuilder.rb

Overview

Helper class used by PathParser

Constant Summary collapse

@@attribute_regex =

Regex for parsing path if the form element@attribute where [index] and @attribute are optional

/^@(\w+)$/
@@node_regex =
/^(\w+)(?:\[(\d+)\])?(?:@(\w+))?$/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(allow_document, nodes) ⇒ Node

Nodes is path.split(‘/’)



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/ec2/amitools/xmlbuilder.rb', line 99

def initialize(allow_document, nodes)
  if allow_document && nodes[0] == ''
    @document = true
    nodes.shift
    return
  end
  nodes.shift while nodes[0] == ''
  node = nodes.shift
  if (match = @@node_regex.match(node))
    @element = match[1]
    @index = match[2].to_i || 0
  elsif (match = @@attribute_regex.match(node))
    @attribute = match[1]
  else
    raise 'Invalid path: Node must be of the form element[index] or @attribute' if document
  end
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



91
92
93
# File 'lib/ec2/amitools/xmlbuilder.rb', line 91

def attribute
  @attribute
end

#documentObject (readonly)

Returns the value of attribute document.



88
89
90
# File 'lib/ec2/amitools/xmlbuilder.rb', line 88

def document
  @document
end

#elementObject (readonly)

Returns the value of attribute element.



89
90
91
# File 'lib/ec2/amitools/xmlbuilder.rb', line 89

def element
  @element
end

#indexObject (readonly)

Returns the value of attribute index.



90
91
92
# File 'lib/ec2/amitools/xmlbuilder.rb', line 90

def index
  @index
end