diff --git a/lib/oga/xpath/evaluator.rb b/lib/oga/xpath/evaluator.rb index f763922..1d01f0d 100644 --- a/lib/oga/xpath/evaluator.rb +++ b/lib/oga/xpath/evaluator.rb @@ -768,6 +768,17 @@ module Oga return ast_node.children[0].to_f end + ## + # Processes an `(float)` node. + # + # @param [Oga::XPath::Node] ast_node + # @param [Oga::XML::NodeSet] context + # @return [Float] + # + def on_float(ast_node, context) + return ast_node.children[0] + end + ## # Processes a `(string)` node. # diff --git a/spec/oga/xpath/evaluator/types/float_spec.rb b/spec/oga/xpath/evaluator/types/float_spec.rb new file mode 100644 index 0000000..b236377 --- /dev/null +++ b/spec/oga/xpath/evaluator/types/float_spec.rb @@ -0,0 +1,19 @@ +require 'spec_helper' + +describe Oga::XPath::Evaluator do + context 'float types' do + before do + document = parse('') + evaluator = described_class.new(document) + @number = evaluator.evaluate('1.2') + end + + example 'return literal integers' do + @number.should == 1.2 + end + + example 'return integers as floats' do + @number.is_a?(Float).should == true + end + end +end