Module: ASpaceImport::CSVConvert::ClassMethods
- Defined in:
- backend/app/converters/lib/csv_converter.rb
Instance Method Summary collapse
Instance Method Details
#configuration ⇒ Object
9 10 11 |
# File 'backend/app/converters/lib/csv_converter.rb', line 9 def configuration @configuration ||= self.configure end |
#configure_cell_handlers(row) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'backend/app/converters/lib/csv_converter.rb', line 14 def configure_cell_handlers(row) headers = row.map {|s| s ||= ""; s.strip}.reject {|s| s.empty? } c = configuration bad_headers = [] headers.each {|h| bad_headers << h unless h.match /^[a-z]*_[a-z0-9_]*$/ } if !bad_headers.empty? raise CSVSyntaxException.new(:bad_headers, bad_headers) end headers.each {|h| bad_headers << h unless c.has_key?(h)} if !bad_headers.empty? # raise CSVSyntaxException.new(:unconfigured_headers, bad_headers) end cell_handlers = headers.map {|h| c.has_key?(h) ? CellHandler.new(*[*c[h], h].reverse) : nil } [cell_handlers, bad_headers] end |