diff --git a/lib/qbxml/types.rb b/lib/qbxml/types.rb index 2e69d3a..2c62232 100644 --- a/lib/qbxml/types.rb +++ b/lib/qbxml/types.rb @@ -5,7 +5,7 @@ module Qbxml::Types :qbpos => :qbposxml }.freeze - FLOAT_CAST = Proc.new {|d| d ? Float(d) : 0.0} + FLOAT_CAST = Proc.new {|d| d ? d.to_f : 0.0} BOOL_CAST = Proc.new {|d| d ? (d.to_s.downcase == 'true' ? true : false) : false } DATE_CAST = Proc.new {|d| d ? Date.parse(d).strftime("%Y-%m-%d") : Date.today.strftime("%Y-%m-%d") } TIME_CAST = Proc.new {|d| d ? Time.parse(d).xmlschema : Time.now.xmlschema } diff --git a/test/unit/xml_to_hash_test.rb b/test/unit/xml_to_hash_test.rb index 02825b6..7dbdbad 100644 --- a/test/unit/xml_to_hash_test.rb +++ b/test/unit/xml_to_hash_test.rb @@ -46,6 +46,79 @@ def test_array_with_one_element assert_equal h, qbxml.from_qbxml("\n\n \n \n abc\n \n \n\n") end + def test_float_percentage + qbxml = Qbxml.new + h = { + "qbxml" => { + "xml_attributes" => {}, + "qbxml_msgs_rs" => { + "xml_attributes" => {}, + "item_query_rs" => { + "xml_attributes" => { + "requestID" => "Retrieve items", + "statusCode" => "0", + "statusSeverity" => "Info", + "statusMessage" => "Status OK", + "iteratorRemainingCount" => "0", + "iteratorID" => "{10c05cbd-b25b-4a85-8aa0-8bce89e6e900}" + }, + "item_service_ret" => { + "xml_attributes" => {}, + "list_id" => "80000005-1468535148", + "time_created" => "2016-07-14T15:25:48-08:00", + "time_modified" => "2016-07-14T15:25:48-08:00", + "edit_sequence" => "1468535148", + "name" => "let's get intuit", + "full_name" => "let's get intuit", + "is_active" => true, + "sublevel" => 0, + "sales_or_purchase" => { + "xml_attributes" => {}, + "price_percent" => 18.0, + "account_ref" => { + "xml_attributes" => {}, + "list_id" => "80000015-1457547358", + "full_name" => "Repairs and Maintenance" + } + } + } + } + } + } + } -end + xml = <<-XML + + + + + 80000005-1468535148 + 2016-07-14T15:25:48-08:00 + 2016-07-14T15:25:48-08:00 + 1468535148 + let's get intuit + let's get intuit + true + 0 + + 18.0% + + 80000015-1457547358 + Repairs and Maintenance + + + + + + + XML + assert_equal h, qbxml.from_qbxml(xml) + end + +end