Class: CSVSafe

Inherits:
CSV
  • Object
show all
Defined in:
lib/csv-safe.rb

Overview

Decorate the built in CSV library Override << to sanitize incoming rows Override initialize to add a converter that will sanitize fields being read

Instance Method Summary collapse

Constructor Details

#initialize(data, converters: nil, **options) ⇒ CSVSafe

Returns a new instance of CSVSafe.



9
10
11
12
13
# File 'lib/csv-safe.rb', line 9

def initialize(data, converters: nil, **options)
  updated_converters = converters || []
  updated_converters << lambda(&method(:sanitize_field))
  super(data, **options.merge(converters: updated_converters))
end

Instance Method Details

#<<(row) ⇒ Object Also known as: add_row, puts



15
16
17
# File 'lib/csv-safe.rb', line 15

def <<(row)
  super(sanitize_row(row))
end