Class: CocoaXML::NodeSet
- Inherits:
-
Array
- Object
- Array
- CocoaXML::NodeSet
- Defined in:
- lib/cocoa-xml/nodeset.rb
Instance Method Summary collapse
-
#[](attr) ⇒ Array<String, nil>
Get the value of the attribute for each node in set.
-
#css(selector) ⇒ NodeSet<NSXMLNode, String>
Perform selector on each element in set.
-
#text ⇒ String
(also: #inner_text)
Collect all the texts of nodes in set and join together.
-
#to_s ⇒ String
Collect all the #to_s representations of elements in array.
-
#xpath(query) ⇒ NodeSet<NSXMLNode>
Perform XPath selection on each node in set.
-
#xquery(query) ⇒ NodeSet<NSXMLNode, String>
Perform XQuery on each node in set.
Instance Method Details
#[](attr) ⇒ Array<String, nil>
Get the value of the attribute for each node in set
53 54 55 |
# File 'lib/cocoa-xml/nodeset.rb', line 53 def [](attr) collect { |node| node[attr] }.flatten end |
#css(selector) ⇒ NodeSet<NSXMLNode, String>
TODO:
This will bomb if the node has String elements in it
Perform selector on each element in set
24 25 26 |
# File 'lib/cocoa-xml/nodeset.rb', line 24 def css(selector) xpath ::Nokogiri::CSS::xpath_for(selector, :prefix => ".//").join end |
#text ⇒ String Also known as: inner_text
Collect all the texts of nodes in set and join together
6 7 8 |
# File 'lib/cocoa-xml/nodeset.rb', line 6 def text collect { |node| (node.respond_to?(:to_str) && node.to_str) || node.text }.flatten.join end |
#to_s ⇒ String
Collect all the #to_s representations of elements in array
14 15 16 |
# File 'lib/cocoa-xml/nodeset.rb', line 14 def to_s collect { |node| node.to_s }.join end |
#xpath(query) ⇒ NodeSet<NSXMLNode>
TODO:
This will bomb if the node has String elements in it
Perform XPath selection on each node in set
44 45 46 47 |
# File 'lib/cocoa-xml/nodeset.rb', line 44 def xpath(query) query.sub! %r{^//}, '' # Roots searches to start from nodes NodeSet.new(collect { |node| node.xpath(query) }.flatten) end |
#xquery(query) ⇒ NodeSet<NSXMLNode, String>
TODO:
This will bomb if the node has String elements in it
Perform XQuery on each node in set
34 35 36 37 |
# File 'lib/cocoa-xml/nodeset.rb', line 34 def xquery(query) query.sub! %r{^//}, '' # Root searches to start from nodes NodeSet.new(collect { |node| node.xquery(query) }.flatten) end |