Module: CSVDecision::Dictionary Private

Defined in:
lib/csv_decision/dictionary.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.

Parse the CSV file’s header row. These methods are only required at table load time.

Defined Under Namespace

Classes: Entry

Class Method Summary collapse

Class Method Details

.add_name(columns:, name:, out: false) ⇒ Hash{Symbol=>[:in, Integer]}

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.

Add a new symbol to the dictionary of named input and output columns.

Parameters:

  • columns ({Symbol=>Symbol})

    Hash of column names with key values :in or :out.

  • name (Symbol)

    Symbolized column name.

  • out (false, Index) (defaults to: false)

    False if an input column, otherwise the index of the output column.

Returns:

  • (Hash{Symbol=>[:in, Integer]})

    Column dictionary updated with the new name.



17
18
19
20
21
22
# File 'lib/csv_decision/dictionary.rb', line 17

def self.add_name(columns:, name:, out: false)
  Validate.name(columns: columns, name: name, out: out)

  columns[name] = out ? out : :in
  columns
end

.build(header:, dictionary:) ⇒ Columns::Dictionary

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.

Classify and build a dictionary of all input and output columns by parsing the header row.

Parameters:

  • header (Array<String>)

    The header row after removing any empty columns.

  • dictionary (Columns::Dictionary)

    Table’s columns dictionary.

Returns:



121
122
123
124
125
126
127
# File 'lib/csv_decision/dictionary.rb', line 121

def self.build(header:, dictionary:)
  header.each_with_index do |cell, index|
    dictionary = parse_cell(cell: cell, index: index, dictionary: dictionary)
  end

  dictionary
end