class Eco::API::Common::People::DefaultParsers::XLSParser
Attributes
already_required[RW]
file[R]
Public Instance Methods
parser(file, deps)
click to toggle source
# File lib/eco/api/common/people/default_parsers/xls_parser.rb, line 7 def parser(file, deps) @file = file rows.tap do |rws| @file = nil rws.each do |row| to_string!(row) end end end
serializer(array_hash, deps)
click to toggle source
# File lib/eco/api/common/people/default_parsers/xls_parser.rb, line 17 def serializer(array_hash, deps) raise "Not implemented. TODO: using axlsx or rubyXL gems. See: https://spin.atomicobject.com/2017/03/22/parsing-excel-files-ruby/" end
Private Instance Methods
headers()
click to toggle source
# File lib/eco/api/common/people/default_parsers/xls_parser.rb, line 32 def headers logger.warn("Headers detection is using your fields_map.json file (native behaviour)") session.fields_mapper.list(:external).uniq end
require_reading_libs!()
click to toggle source
# File lib/eco/api/common/people/default_parsers/xls_parser.rb, line 61 def require_reading_libs! return if already_required require 'roo' require 'roo-xls' already_required = true end
rows(target = headers)
click to toggle source
# File lib/eco/api/common/people/default_parsers/xls_parser.rb, line 50 def rows(target = headers) begin spreadheet.parse(header_search: target, clean: true) rescue Roo::HeaderRowNotFoundError => e missing = JSON.parse(e.message) logger.warn("The input file is missing these headers: #{missing}") present = target - missing rows(present) end end
sheet_name()
click to toggle source
# File lib/eco/api/common/people/default_parsers/xls_parser.rb, line 37 def sheet_name 0 end
spreadheet(name_or_index = sheet_name)
click to toggle source
# File lib/eco/api/common/people/default_parsers/xls_parser.rb, line 46 def spreadheet(name_or_index = sheet_name) workbook.sheet(name_or_index) end
to_string!(row)
click to toggle source
# File lib/eco/api/common/people/default_parsers/xls_parser.rb, line 23 def to_string!(row) row.transform_values! do |val| next nil unless val next val if val.is_a?(String) val.to_s end end
workbook()
click to toggle source
# File lib/eco/api/common/people/default_parsers/xls_parser.rb, line 41 def workbook require_reading_libs! Roo::Spreadsheet.open(file) end