Module: CSVDecision2::Data Private

Defined in:
lib/csv_decision2/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

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.

Parameters:

  • data (Pathname, File, Array<Array<String>>, String)

    input data given as a CSV file, array of arrays or CSV string.

Returns:

  • (Boolean)

    Set to true if the input data is passed as a File or Pathname.



34
35
36
# File 'lib/csv_decision2/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.

Parameters:

  • empty_columns (Array<Index>)
  • data (Pathname, File, Array<Array<String>>, String)

    input data given as a CSV file, array of arrays or CSV string.

Returns:

  • (Array<Array<String>>)

    Data array stripped of empty columns.



43
44
45
46
47
48
49
# File 'lib/csv_decision2/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.

Parameters:

  • data (Pathname, File, Array<Array<String>>, String)

    input data given as a CSV file, array of arrays or CSV string.

Returns:

  • (Array<Array<String>>)

    Data array stripped of empty rows.



26
27
28
# File 'lib/csv_decision2/data.rb', line 26

def self.to_array(data:)
  strip_rows(data: data_array(data))
end