Class: Mixml::Selection
- Inherits:
-
Object
- Object
- Mixml::Selection
- Defined in:
- lib/mixml/selection.rb
Overview
Selection of XML nodes
Instance Attribute Summary collapse
-
#nodesets ⇒ Nokogiri::XML::NodeSet
readonly
Selected nodes.
Instance Method Summary collapse
-
#append(template) ⇒ Object
Append children to node.
-
#initialize(nodesets) ⇒ Selection
constructor
Initialize a new selection.
-
#remove ⇒ Object
Remove selected nodes from the document.
-
#rename(template) ⇒ Object
Rename selected nodes with a template.
-
#replace(template) ⇒ Object
Replace selected nodes with a template.
-
#value(template) ⇒ Object
Set the value selected nodes with a template.
-
#write(template = nil) ⇒ Object
Print selected nodes to stdout.
Constructor Details
#initialize(nodesets) ⇒ Selection
Initialize a new selection
13 14 15 |
# File 'lib/mixml/selection.rb', line 13 def initialize(nodesets) @nodesets = nodesets end |
Instance Attribute Details
#nodesets ⇒ Nokogiri::XML::NodeSet (readonly)
Returns Selected nodes.
8 9 10 |
# File 'lib/mixml/selection.rb', line 8 def nodesets @nodesets end |
Instance Method Details
#append(template) ⇒ Object
Append children to node
57 58 59 60 61 62 63 64 |
# File 'lib/mixml/selection.rb', line 57 def append(template) template = template.to_mixml_template each_node do |node| value = template.evaluate(node) node << value end end |
#remove ⇒ Object
Remove selected nodes from the document
18 19 20 21 22 |
# File 'lib/mixml/selection.rb', line 18 def remove each_node do |node| node.remove end end |
#rename(template) ⇒ Object
Rename selected nodes with a template
81 82 83 84 85 86 87 88 |
# File 'lib/mixml/selection.rb', line 81 def rename(template) template = template.to_mixml_template each_node do |node| value = template.evaluate(node) node.name = value end end |
#replace(template) ⇒ Object
Replace selected nodes with a template
45 46 47 48 49 50 51 52 |
# File 'lib/mixml/selection.rb', line 45 def replace(template) template = template.to_mixml_template each_node do |node| value = template.evaluate(node) node.replace(value) end end |
#value(template) ⇒ Object
Set the value selected nodes with a template
69 70 71 72 73 74 75 76 |
# File 'lib/mixml/selection.rb', line 69 def value(template) template = template.to_mixml_template each_node do |node| value = template.evaluate(node) node.value = value end end |
#write(template = nil) ⇒ Object
Print selected nodes to stdout
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/mixml/selection.rb', line 27 def write(template = nil) if not template.nil? then template = template.to_mixml_template end each_node do |node| if template.nil? then node.write_xml_to($stdout) puts else puts template.evaluate(node) end end end |