From 37101a6b64afb0d2e9dd0bc44a6e39d395a08a21 Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Fri, 7 Jun 2019 02:45:19 +0800 Subject: [PATCH] Extract build_entries_from_rows for product import --- app/models/product_import/product_importer.rb | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/app/models/product_import/product_importer.rb b/app/models/product_import/product_importer.rb index e7a7f8792f..5d8a3176d1 100644 --- a/app/models/product_import/product_importer.rb +++ b/app/models/product_import/product_importer.rb @@ -253,13 +253,7 @@ module ProductImport end def build_entries - rows.each_with_index do |row, i| - row_data = Hash[[headers, row].transpose] - entry = SpreadsheetEntry.new(row_data) - entry.line_number = i + 2 - @entries.push entry - end - @entries + @entries = build_entries_from_rows(rows) end def save_all_valid @@ -272,5 +266,14 @@ module ProductImport return unless @file.path == Rails.root.join('tmp', 'product_import').to_s File.delete(@file) end + + def build_entries_from_rows(rows) + rows.each_with_index.inject([]) do |entries, (row, i)| + row_data = Hash[[headers, row].transpose] + entry = SpreadsheetEntry.new(row_data) + entry.line_number = i + 2 + entries.push entry + end + end end end