def visit_function node
msg = "visit_function_#{node.value.first.gsub(/[(]/, '')}""visit_function_#{node.value.first.gsub(/[(]/, '')}"
return self.send(msg, node) if self.respond_to?(msg)
case node.value.first
when /^text\(/
'child::text()'
when /^self\(/
"self::#{node.value[1]}"
when /^(eq|nth|nth-of-type|nth-child)\(/
if node.value[1].is_a?(Nokogiri::CSS::Node) and node.value[1].type == :AN_PLUS_B
an_plus_b(node.value[1])
else
"position() = " + node.value[1]
end
when /^(first|first-of-type)\(/
"position() = 1"
when /^(last|last-of-type)\(/
"position() = last()"
when /^(nth-last-child|nth-last-of-type)\(/
"position() = last() - #{node.value[1]}"
when /^contains\(/
"contains(., #{node.value[1]})"
when /^gt\(/
"position() > #{node.value[1]}"
when /^only-child\(/
"last() = 1"
when /^comment\(/
"comment()"
else
args = ['.'] + node.value[1..-1]
"#{node.value.first}#{args.join(', ')})"
end
end