Skip to content

Commit f93d594

Browse files
authored
Merge pull request #19 from mavenlink/float_percentage
Handle parsing of % character in a float type
2 parents d6a9fbc + 8b27b31 commit f93d594

File tree

2 files changed

+77
-2
lines changed

2 files changed

+77
-2
lines changed

lib/qbxml/types.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module Qbxml::Types
55
:qbpos => :qbposxml
66
}.freeze
77

8-
FLOAT_CAST = Proc.new {|d| d ? Float(d) : 0.0}
8+
FLOAT_CAST = Proc.new {|d| d ? d.to_f : 0.0}
99
BOOL_CAST = Proc.new {|d| d ? (d.to_s.downcase == 'true' ? true : false) : false }
1010
DATE_CAST = Proc.new {|d| d ? Date.parse(d).strftime("%Y-%m-%d") : Date.today.strftime("%Y-%m-%d") }
1111
TIME_CAST = Proc.new {|d| d ? Time.parse(d).xmlschema : Time.now.xmlschema }

test/unit/xml_to_hash_test.rb

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,80 @@ def test_array_of_strings
2626
assert_equal h, qbxml.from_qbxml("<?qbxml version=\"7.0\"?>\n<QBXML>\n <QBXMLMsgsRq>\n <InvoiceQueryRq>\n <IncludeRetElement>TxnID</IncludeRetElement>\n <IncludeRetElement>RefNumber</IncludeRetElement>\n </InvoiceQueryRq>\n </QBXMLMsgsRq>\n</QBXML>\n")
2727
end
2828

29-
end
29+
def test_float_percentage
30+
qbxml = Qbxml.new
3031

32+
h = {
33+
"qbxml" => {
34+
"xml_attributes" => {},
35+
"qbxml_msgs_rs" => {
36+
"xml_attributes" => {},
37+
"item_query_rs" => {
38+
"xml_attributes" => {
39+
"requestID" => "Retrieve items",
40+
"statusCode" => "0",
41+
"statusSeverity" => "Info",
42+
"statusMessage" => "Status OK",
43+
"iteratorRemainingCount" => "0",
44+
"iteratorID" => "{10c05cbd-b25b-4a85-8aa0-8bce89e6e900}"
45+
},
46+
"item_service_ret" => {
47+
"xml_attributes" => {},
48+
"list_id" => "80000005-1468535148",
49+
"time_created" => "2016-07-14T15:25:48-08:00",
50+
"time_modified" => "2016-07-14T15:25:48-08:00",
51+
"edit_sequence" => "1468535148",
52+
"name" => "let's get intuit",
53+
"full_name" => "let's get intuit",
54+
"is_active" => true,
55+
"sublevel" => 0,
56+
"sales_or_purchase" => {
57+
"xml_attributes" => {},
58+
"price_percent" => 18.0,
59+
"account_ref" => {
60+
"xml_attributes" => {},
61+
"list_id" => "80000015-1457547358",
62+
"full_name" => "Repairs and Maintenance"
63+
}
64+
}
65+
}
66+
}
67+
}
68+
}
69+
}
70+
71+
xml = <<-XML
72+
<QBXML>
73+
<QBXMLMsgsRs>
74+
<ItemQueryRs requestID="Retrieve items"
75+
statusCode="0"
76+
statusSeverity="Info"
77+
statusMessage="Status OK"
78+
iteratorRemainingCount="0"
79+
iteratorID="{10c05cbd-b25b-4a85-8aa0-8bce89e6e900}">
80+
<ItemServiceRet>
81+
<ListID>80000005-1468535148</ListID>
82+
<TimeCreated>2016-07-14T15:25:48-08:00</TimeCreated>
83+
<TimeModified>2016-07-14T15:25:48-08:00</TimeModified>
84+
<EditSequence>1468535148</EditSequence>
85+
<Name>let's get intuit</Name>
86+
<FullName>let's get intuit</FullName>
87+
<IsActive>true</IsActive>
88+
<Sublevel>0</Sublevel>
89+
<SalesOrPurchase>
90+
<PricePercent>18.0%</PricePercent>
91+
<AccountRef>
92+
<ListID>80000015-1457547358</ListID>
93+
<FullName>Repairs and Maintenance</FullName>
94+
</AccountRef>
95+
</SalesOrPurchase>
96+
</ItemServiceRet>
97+
</ItemQueryRs>
98+
</QBXMLMsgsRs>
99+
</QBXML>
100+
XML
101+
102+
assert_equal h, qbxml.from_qbxml(xml)
103+
end
104+
105+
end

0 commit comments

Comments
 (0)