lib/securetrading/base_model.rb in securetrading-0.3.0 vs lib/securetrading/base_model.rb in securetrading-0.3.1

- old
+ new

@@ -1,15 +1,27 @@ module Securetrading class BaseModel def initialize(attrs_hash = {}) - @attributes_hash = attrs_hash.presence && attrs_hash.stringify_keys + @attributes_hash = attrs_hash.presence && + attrs_hash.transform_keys! { |k| k.to_s.tr('__', '') } end def ox_xml - XmlDoc.elements(xml_tag_name => @attributes_hash).first + ox = ox_from_values + sub_classes.each do |sub_class_name| + next unless attributes_hash.key?(sub_class_name) + ox << send(sub_class_name).ox_xml + end + ox end private + + def ox_from_values + XmlDoc + .elements(xml_tag_name => @attributes_hash.except(*sub_classes)) + .first + end def xml_tag_name self.class.name.demodulize.downcase end