Class: CSVConverter::Converters::ArrayConverter
- Inherits:
-
BaseConverter
- Object
- BaseConverter
- CSVConverter::Converters::ArrayConverter
- Defined in:
- lib/csv_converter/converters/array_converter.rb
Overview
Converts a string separated by a given char into an array of strings.
Instance Attribute Summary
Attributes inherited from BaseConverter
Instance Method Summary collapse
-
#call ⇒ Array
Converts data into an array by splitting the string on the separator provided in the mappings.
-
#call! ⇒ Array
Converts data into an array by splitting the string on the separator provided in the mappings.
-
#initialize(raw_data, options = { separator: ',' }) ⇒ ArrayConverter
constructor
A new instance of ArrayConverter.
Methods inherited from BaseConverter
Constructor Details
#initialize(raw_data, options = { separator: ',' }) ⇒ ArrayConverter
A new instance of ArrayConverter.
12 13 14 15 16 |
# File 'lib/csv_converter/converters/array_converter.rb', line 12 def initialize(raw_data, = { separator: ',' }) super(raw_data, ) end |
Instance Method Details
#call ⇒ Array
Converts data into an array by splitting the string on the separator provided in the mappings.
20 21 22 23 24 |
# File 'lib/csv_converter/converters/array_converter.rb', line 20 def call call! rescue CSVConverter::Error nullable_object end |
#call! ⇒ Array
Converts data into an array by splitting the string on the separator provided in the mappings.
28 29 30 31 32 |
# File 'lib/csv_converter/converters/array_converter.rb', line 28 def call! data.split([:separator]).map(&:strip) rescue StandardError => e raise CSVConverter::Error.new(e., ) end |