I’m importing sales data from iTunes successfully using:
FasterCSV.parse(uploaded_io, {:headers => true, :col_sep =>"\t"}).each do |row_data|
new_record = AppleSale.new(
'provider' => row_data[0],
'provider_country' => row_data[1],
'vendor_identifier' => row_data[2],
'upc' => row_data[3],
'isrc' => row_data[4],
'artist_show' => row_data[5],
'title' => row_data[6],
'label_studio_network' => row_data[7],
'product_type_identifier' => row_data[8],
'units' => row_data[9],
'royalty_price' => row_data[10],
'download_date' => row_data[11],
'order_id' => row_data[12],
'postal_code' => row_data[13],
'customer_identifier' => row_data[14],
'report_date' => row_data[15],
'sale_return' => row_data[16],
'customer_currency' => row_data[17],
'country_code' => row_data[18],
'royalty_currency' => row_data[19],
'preorder' => row_data[20],
'isan' => row_data[21],
'customer_price' => row_data[22],
'apple_identifier' => row_data[23],
'cma' => row_data[24],
'asset_content_flavor' => row_data[25],
'vendor_order_code' => row_data[26],
'grid' => row_data[27],
'promo_code' => row_data[28],
'parent_identifier' => row_data[29]
)
new_record.save
end
‘vendor_order_code’ however contains values like ‘0711297494143_CADE70900648’ that i’d like to split on the underscore and store in two separate (new) columns. Not all entries have a value like this, some just contain the first part (a UPC). I realise there are already UPC and ISRC columns provided but these aren’t populated in a way that’s useful to me, splitting the vendor_order_code is the only way I can do what I need to do.
Can anyone suggest the correct way of doing this? I know the below is complete nonsense, but i’m thinking something along the lines of:
'vendor_order_code' => row_data[26],
'vendor_order_code_UPC' => row_data[26].split("_")...and save just the first half regardless of whether split occurred.
'vendor_order_code_ISRC' => row_data[26].split("_")..and save just the second half if it exists
No need for multiple splits and/or conditionals; just
matchonce per row.