Class: XMLNode
- Inherits:
-
Struct
- Object
- Struct
- XMLNode
- Defined in:
- lib/dagger/ox_extension.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#children ⇒ Object
Returns the value of attribute children.
-
#name ⇒ Object
Returns the value of attribute name.
-
#text ⇒ Object
Returns the value of attribute text.
Instance Method Summary collapse
-
#[](key) ⇒ Object
this lets us traverse an parsed object like this: doc[:grandchild].value.
-
#all(key) ⇒ Object
returns all matching nodes.
-
#first(key) ⇒ Object
returns first matching node.
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes
3 4 5 |
# File 'lib/dagger/ox_extension.rb', line 3 def attributes @attributes end |
#children ⇒ Object
Returns the value of attribute children
3 4 5 |
# File 'lib/dagger/ox_extension.rb', line 3 def children @children end |
#name ⇒ Object
Returns the value of attribute name
3 4 5 |
# File 'lib/dagger/ox_extension.rb', line 3 def name @name end |
#text ⇒ Object
Returns the value of attribute text
3 4 5 |
# File 'lib/dagger/ox_extension.rb', line 3 def text @text end |
Instance Method Details
#[](key) ⇒ Object
this lets us traverse an parsed object like this: doc[:grandchild].value
6 7 8 9 |
# File 'lib/dagger/ox_extension.rb', line 6 def [](key) found = children.select { |node| node.name.to_s == key.to_s } found.empty? ? nil : found.size == 1 ? found.first : found end |
#all(key) ⇒ Object
returns all matching nodes
25 26 27 28 29 30 |
# File 'lib/dagger/ox_extension.rb', line 25 def all(key) found = self[key] direct = found.is_a?(XMLNode) ? [found] : found || [] indirect = children.map { |ch| ch.all(key) }.flatten.compact direct + indirect end |
#first(key) ⇒ Object
returns first matching node
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/dagger/ox_extension.rb', line 12 def first(key) if found = self[key] found.is_a?(XMLNode) ? found : found.first else children.find do |ch| if res = ch.first(key) return res end end end end |