class MoneyNode
Public Class Methods
new(*args)
click to toggle source
Calls superclass method
# File lib/support/xml_mapping/money_node.rb, line 5 def initialize(*args) @path,*args = super(*args) @amount_path = XML::XXPath.new(@path) @currency_path = XML::XXPath.new(@path + "/@currencyID") end
Public Instance Methods
extract_attr_value(xml)
click to toggle source
# File lib/support/xml_mapping/money_node.rb, line 11 def extract_attr_value(xml) amount, currency = default_when_xpath_err{ [(@amount_path.first(xml).text.to_f * 100).to_i, @currency_path.first(xml).text] } Money.new(amount, currency) end
set_attr_value(xml, value)
click to toggle source
# File lib/support/xml_mapping/money_node.rb, line 18 def set_attr_value(xml, value) raise "Not a Money object: #{value}" unless Money === value @amount_path.first(xml, :ensure_created => true).text = sprintf("%.2f", value.cents.to_f / 100 ) @currency_path.first(xml, :ensure_created => true).text = value.currency end