Merge pull request #932 from okriuchykhin/ok_SCI_1915

Improve XLSX parsing with Roo [SCI-1915]
This commit is contained in:
okriuchykhin 2018-01-12 14:57:17 +01:00 committed by GitHub
commit 00927be287
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 4 deletions

View file

@ -132,8 +132,7 @@ class Repository < ActiveRecord::Base
end
total_nr += 1
# Creek XLSX parser returns Hash of the row, Roo - Array
row = row.is_a?(Hash) ? row.values.map(&:to_s) : row.map(&:to_s)
row = SpreadsheetParser.parse_row(row, sheet)
record_row = RepositoryRow.new(name: row[name_index],
repository: self,

View file

@ -80,8 +80,7 @@ class Team < ActiveRecord::Base
next
end
total_nr += 1
# Creek XLSX parser returns Hash of the row, Roo - Array
row = row.is_a?(Hash) ? row.values.map(&:to_s) : row.map(&:to_s)
row = SpreadsheetParser.parse_row(row, sheet)
sample = Sample.new(name: row[sname_index],
team: self,

View file

@ -52,4 +52,15 @@ class SpreadsheetParser
end
return header, columns
end
def self.parse_row(row, sheet)
# Creek XLSX parser returns Hash of the row, Roo - Array
if row.is_a?(Hash)
row.values.map(&:to_s)
elsif sheet.is_a?(Roo::Excelx)
row.map { |cell| cell.value.to_s }
else
row.map(&:to_s)
end
end
end