lib/securetrading/xml_doc.rb in securetrading-0.1.0 vs lib/securetrading/xml_doc.rb in securetrading-0.2.0

- old
+ new

@@ -12,22 +12,25 @@ root[:version] = '3.67' root << alias_el << request_el @doc << root end + # rubocop:disable Metrics/MethodLength def self.elements(hash) - return unless hash.present? - hash.map do |k, v| + return '' unless hash.present? + hash.flat_map do |k, v| + return v.flat_map { |e| elements(k => e) } if v.is_a?(Array) el = new_element(k.to_s) - if v.is_a? Hash + if v.is_a?(Hash) elements(v).each { |e| el << e } else el << v.to_s end - el + [el] end end + # rubocop:enable Metrics/MethodLength def self.new_element(name) Ox::Element.new(name) end @@ -35,25 +38,16 @@ def new_element(name) self.class.new_element(name) end - def operation - self.class.elements( - operation: { - sitereference: Securetrading.config.site_reference, - accounttypedescription: @account_type - } - ).first - end - def alias_el self.class.elements(alias: Securetrading.config.user).first end def request_el el = new_element('request') el[:type] = @request_type - el << operation + el end end end