2014-11-04 22:33:42 +00:00
|
|
|
module Oga
|
|
|
|
module EvaluationHelpers
|
2014-11-09 17:47:20 +00:00
|
|
|
##
|
|
|
|
# @param [Oga::XML::Document] document
|
|
|
|
# @param [String] xpath
|
|
|
|
# @return [Oga::XML::NodeSet]
|
|
|
|
#
|
2019-11-29 14:21:45 +00:00
|
|
|
def evaluate_xpath(document, xpath = self.class.description, namespaces: nil)
|
2015-07-07 23:10:37 +00:00
|
|
|
ast = parse_xpath(xpath)
|
2019-11-29 14:21:45 +00:00
|
|
|
compiler = Oga::XPath::Compiler.new(namespaces: namespaces)
|
2015-07-07 23:10:37 +00:00
|
|
|
block = compiler.compile(ast)
|
|
|
|
|
|
|
|
block.call(document)
|
2014-11-09 17:47:20 +00:00
|
|
|
end
|
|
|
|
|
2014-11-04 22:33:42 +00:00
|
|
|
##
|
|
|
|
# Parses and evaluates a CSS expression.
|
|
|
|
#
|
|
|
|
# @param [Oga::XML::Document] document
|
|
|
|
# @param [String] css
|
|
|
|
# @return [Oga::XML::NodeSet]
|
|
|
|
#
|
2015-08-26 20:35:13 +00:00
|
|
|
def evaluate_css(document, css = self.class.description)
|
2015-07-07 23:10:37 +00:00
|
|
|
ast = parse_css(css)
|
|
|
|
compiler = Oga::XPath::Compiler.new
|
|
|
|
block = compiler.compile(ast)
|
2014-11-04 22:33:42 +00:00
|
|
|
|
2015-07-07 23:10:37 +00:00
|
|
|
block.call(document)
|
2014-11-04 22:33:42 +00:00
|
|
|
end
|
|
|
|
end # EvaluationHelpers
|
|
|
|
end # Oga
|