Class: CSVSafe
- Inherits:
-
CSV
- Object
- CSV
- CSVSafe
- 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
- #<<(row) ⇒ Object (also: #add_row, #puts)
-
#initialize(data, converters: nil, **options) ⇒ CSVSafe
constructor
A new instance of CSVSafe.
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, **) updated_converters = converters || [] updated_converters << lambda(&method(:sanitize_field)) super(data, **.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 |