Module: CSVDecision::Data Private
- Defined in:
- lib/csv_decision/data.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Methods to load data from a file, CSV string or an array of arrays.
Class Method Summary collapse
-
.input_file?(data) ⇒ Boolean
private
If the input is a file name return true, otherwise false.
-
.strip_columns(data:, empty_columns:) ⇒ Array<Array<String>>
private
Strip the empty columns from the input data rows.
-
.to_array(data:) ⇒ Array<Array<String>>
private
Parse the input data which may either be a file path name, CSV string or array of arrays.
Class Method Details
.input_file?(data) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
If the input is a file name return true, otherwise false.
34 35 36 |
# File 'lib/csv_decision/data.rb', line 34 def self.input_file?(data) data.is_a?(Pathname) || data.is_a?(File) end |
.strip_columns(data:, empty_columns:) ⇒ Array<Array<String>>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Strip the empty columns from the input data rows.
43 44 45 46 47 48 49 |
# File 'lib/csv_decision/data.rb', line 43 def self.strip_columns(data:, empty_columns:) # Adjust column indices as we delete columns the rest shift to the left by 1 empty_columns.map!.with_index { |col, index| col - index } # Delete all empty columns from the array of arrays empty_columns.each { |col| data.each_index { |row| data[row].delete_at(col) } } end |
.to_array(data:) ⇒ Array<Array<String>>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Parse the input data which may either be a file path name, CSV string or array of arrays. Strips out empty columns/rows and comment cells.
26 27 28 |
# File 'lib/csv_decision/data.rb', line 26 def self.to_array(data:) strip_rows(data: data_array(data)) end |