Skip to content

Instantly share code, notes, and snippets.

@yorickpeterse
Last active August 29, 2015 14:24
Show Gist options
  • Save yorickpeterse/313501dc4713f861bfbb to your computer and use it in GitHub Desktop.
Save yorickpeterse/313501dc4713f861bfbb to your computer and use it in GitHub Desktop.
lambda do |node, variables = nil|
matched = Oga::XML::NodeSet.new
node.children.each do |node|
if (node.is_a?(Oga::XML::Attribute) || node.is_a?(Oga::XML::Element)) && node.name == "root"
node.children.each do |node|
if (node.is_a?(Oga::XML::Attribute) || node.is_a?(Oga::XML::Element)) && node.name == "a"
if catch(:predicate_matched) do ||
node.children.each do |node|
if (node.is_a?(Oga::XML::Attribute) || node.is_a?(Oga::XML::Element)) && node.name == "b"
throw(:predicate_matched, true)
end
end
nil
end
matched.push(node)
end
end
end
end
end
matched
end
lambda do |node, variables = nil|
matched = Oga::XML::NodeSet.new
node.children.each do |node|
if (node.is_a?(Oga::XML::Attribute) || node.is_a?(Oga::XML::Element)) && node.name == "root"
node.children.each do |node|
if (node.is_a?(Oga::XML::Attribute) || node.is_a?(Oga::XML::Element)) && node.name == "a"
if catch(:predicate_matched) do ||
node.children.each do |node|
if (node.is_a?(Oga::XML::Attribute) || node.is_a?(Oga::XML::Element)) && node.name == "b"
throw(:predicate_matched, true)
end
end
nil
end
matched.push(node)
end
end
end
end
end
matched
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment