Class: MoneyNode
- Inherits:
-
XML::Mapping::SingleAttributeNode
- Object
- XML::Mapping::SingleAttributeNode
- MoneyNode
- Defined in:
- lib/support/xml_mapping/money_node.rb
Instance Method Summary collapse
- #extract_attr_value(xml) ⇒ Object
- #initialize_impl(path) ⇒ Object
- #set_attr_value(xml, value) ⇒ Object
Instance Method Details
#extract_attr_value(xml) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/support/xml_mapping/money_node.rb', line 10 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 |
#initialize_impl(path) ⇒ Object
5 6 7 8 |
# File 'lib/support/xml_mapping/money_node.rb', line 5 def initialize_impl(path) @amount_path = XML::XXPath.new(path + "/") @currency_path = XML::XXPath.new(path + "/@currencyID") end |
#set_attr_value(xml, value) ⇒ Object
17 18 19 20 21 |
# File 'lib/support/xml_mapping/money_node.rb', line 17 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 |