Module: Oga::XML::Querying
Overview
The Querying module provides methods that make it easy to run XPath/CSS queries on XML documents/elements.
Instance Method Summary collapse
-
#at_css(*args) ⇒ Object
Evaluates the given CSS expression and returns the first node in the set.
-
#at_xpath(*args) ⇒ Object
Evaluates the given XPath expression and returns the first node in the set.
-
#css(expression) ⇒ Object
Evaluates the given CSS expression.
-
#xpath(expression, variables = {}) ⇒ Object
Evaluates the given XPath expression.
Instance Method Details
#at_css(*args) ⇒ Object
Evaluates the given CSS expression and returns the first node in the set.
49 50 51 52 53 |
# File 'lib/oga/xml/querying.rb', line 49 def at_css(*args) result = css(*args) result.is_a?(XML::NodeSet) ? result.first : result end |
#at_xpath(*args) ⇒ Object
Evaluates the given XPath expression and returns the first node in the set.
25 26 27 28 29 |
# File 'lib/oga/xml/querying.rb', line 25 def at_xpath(*args) result = xpath(*args) result.is_a?(XML::NodeSet) ? result.first : result end |
#css(expression) ⇒ Object
Evaluates the given CSS expression.
37 38 39 40 41 |
# File 'lib/oga/xml/querying.rb', line 37 def css(expression) ast = CSS::Parser.parse_with_cache(expression) XPath::Evaluator.new(self).evaluate_ast(ast) end |