diff --git a/lib/handsoap.rb b/lib/handsoap.rb index b4ad636..2093108 100644 --- a/lib/handsoap.rb +++ b/lib/handsoap.rb @@ -2,3 +2,4 @@ require 'handsoap/xml_mason' require 'handsoap/xml_query_front' require 'handsoap/service' +require 'bigdecimal' diff --git a/lib/handsoap/xml_query_front.rb b/lib/handsoap/xml_query_front.rb index 3df435c..cc7c84c 100644 --- a/lib/handsoap/xml_query_front.rb +++ b/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. diff --git a/tests/account_test.rb b/tests/account_test.rb index a1c12db..e06b0b8 100644 --- a/tests/account_test.rb +++ b/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 - + '