Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added to_big_decimal to xml_query_front

  • Loading branch information...
commit 81a774f08d3b49077e008df4da270ac85754d479 1 parent 081d728
@mynameisrufus mynameisrufus authored
View
1  lib/handsoap.rb
@@ -2,3 +2,4 @@
require 'handsoap/xml_mason'
require 'handsoap/xml_query_front'
require 'handsoap/service'
+require 'bigdecimal'
View
11 lib/handsoap/xml_query_front.rb
@@ -86,6 +86,9 @@ def to_boolean
def to_date
self.first.to_date if self.any?
end
+ def to_big_decimal(decimal_places = 2)
+ self.first.to_big_decimal(decimal_places) if self.any?
+ end
def to_s
self.first.to_s if self.any?
end
@@ -159,6 +162,14 @@ def to_date
return if t.nil?
Time.iso8601(t)
end
+ # Returns the value of the element as an instance of BigDecimal
+ #
+ # See +to_s+
+ def to_big_decimal(decimal_places = 2)
+ t = self.to_s
+ return if t.nil?
+ BigDecimal.new t, decimal_places
+ end
# Returns the inner text content of this element, or the value (if it's an attr or textnode).
#
# The output is a UTF-8 encoded string, without xml-entities.
View
6 tests/account_test.rb
@@ -56,7 +56,8 @@ def parse_account(node)
:blacklisted => (node/"@blacklisted").to_boolean,
:application_id => (node/"@application-id").to_i,
:amount_used => (node/"@amount-used").to_i,
- :account_id => (node/"@account-id").to_i
+ :account_id => (node/"@account-id").to_i,
+ :credit => (node/"@credit").to_big_decimal
end
end
@@ -71,6 +72,7 @@ def initialize(values = {})
@buy_attempts = values[:buy_attempts]
@blacklisted = values[:blacklisted] || false
@amount_used = values[:amount_used]
+ @credit = values[:credit]
end
def blacklisted?
!! @blacklisted
@@ -91,7 +93,7 @@ def setup
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns1:GetAccountByIdResponse xmlns:ns1="http://schema.example.org/AccountService">
- <account msisdn="12345678" account-id="1" created="2009-08-03T11:28:26+02:00" buy-attempts="42" blacklisted="true" application-id="1" amount-used="123456"/>
+ <account msisdn="12345678" account-id="1" created="2009-08-03T11:28:26+02:00" buy-attempts="42" blacklisted="true" application-id="1" amount-used="123456" credit="24.95"/>
</ns1:GetAccountByIdResponse>
</soap:Body>
</soap:Envelope>'
Please sign in to comment.
Something went wrong with that request. Please try again.