class ParamFilter ORDER_ATTRIBUTE_MAPPINGS = { :bill_city => :billing_city, :bill_address1 => :billing_address_line_1, :bill_zip => :billing_zip, :bill_country => :billing_country, :expiry_date => :expiration_date, :bill_address2 => :billing_address_line_2, :bill_state => :billing_state } def self.select_item_quantities(params) selected = params.select do |key, value| key.to_s =~ /^[A-Z]+-\d+$/ end Hash[*selected.flatten] end def self.select_order_attributes(params) selected = params.select do |key, value| key.to_s =~ /^order\./ end attributes = selected.map do |key, value| [key[6..-1].underscore.to_sym, value] end result_hash = Hash[*attributes.flatten] ORDER_ATTRIBUTE_MAPPINGS.each do |old, new| result_hash[new] = result_hash.delete(old) end result_hash end end