Class: CSVDecision::Columns Private

Inherits:
Object
  • Object
show all
Defined in:
lib/csv_decision/columns.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Dictionary of all this table’s columns - inputs, outputs etc.

Defined Under Namespace

Classes: Dictionary

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table) ⇒ Columns

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.

Returns a new instance of Columns.

Parameters:

  • table (Table)

    Decision table being constructed.

Raises:



178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/csv_decision/columns.rb', line 178

def initialize(table)
  # If a column does not have a valid header cell, then it's empty of data.
  # Return the stripped header row, and remove it from the data array.
  row = Header.strip_empty_columns(rows: table.rows)

  # No header row found?
  raise TableValidationError, 'table has no header row' unless row

  # Build a dictionary of all valid data columns from the header row.
  @dictionary = CSVDecision::Dictionary.build(header: row, dictionary: Dictionary.new)

  freeze
end

Class Method Details

.ins_cell_dictionary(columns:, cell:) ⇒ void

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.

This method returns an undefined value.

Parameters:



30
31
32
33
34
35
# File 'lib/csv_decision/columns.rb', line 30

def self.ins_cell_dictionary(columns:, cell:)
  return unless cell.is_a?(Matchers::Proc)
  return if cell.symbols.nil?

  add_ins_symbols(columns: columns, cell: cell)
end

.ins_dictionary(columns:, row:) ⇒ void

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.

This method returns an undefined value.

Parameters:



23
24
25
# File 'lib/csv_decision/columns.rb', line 23

def self.ins_dictionary(columns:, row:)
  row.each { |cell| ins_cell_dictionary(columns: columns, cell: cell) }
end

.outs_dictionary(columns:, row:) ⇒ void

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.

This method returns an undefined value.

Parameters:



14
15
16
17
18
# File 'lib/csv_decision/columns.rb', line 14

def self.outs_dictionary(columns:, row:)
  row.each_with_index do |cell, index|
    outs_check_cell(columns: columns, cell: cell, index: index)
  end
end

Instance Method Details

#defaultsObject

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.

Input columns with defaults specified



133
134
135
# File 'lib/csv_decision/columns.rb', line 133

def defaults
  @dictionary&.defaults
end

#defaults=(value) ⇒ Object

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.

Set defaults for columns with defaults specified



138
139
140
# File 'lib/csv_decision/columns.rb', line 138

def defaults=(value)
  @dictionary.defaults = value
end

#dictionaryHash{Symbol=>[false, 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.

Returns Dictionary of all input and output column names.

Returns:

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

    Dictionary of all input and output column names.



144
145
146
# File 'lib/csv_decision/columns.rb', line 144

def dictionary
  @dictionary.columns
end

#ifsHash{Index=>Entry}

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: columns hash keyed by column index.

Returns:



162
163
164
# File 'lib/csv_decision/columns.rb', line 162

def ifs
  @dictionary.ifs
end

#input_keysArray<Symbol>

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.

Returns All input column symbols.

Returns:

  • (Array<Symbol>)

    All input column symbols.



173
174
175
# File 'lib/csv_decision/columns.rb', line 173

def input_keys
  @dictionary.columns.select { |_k, v| v == :in }.keys
end

#insHash{Index=>Entry}

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.

Input columns hash keyed by column index.

Returns:



150
151
152
# File 'lib/csv_decision/columns.rb', line 150

def ins
  @dictionary.ins
end

#outsHash{Index=>Entry}

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.

Output columns hash keyed by column index.

Returns:



156
157
158
# File 'lib/csv_decision/columns.rb', line 156

def outs
  @dictionary&.outs
end

#pathsHash{Index=>Entry}

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.

path: columns hash keyed by column index.

Returns:



168
169
170
# File 'lib/csv_decision/columns.rb', line 168

def paths
  @dictionary.paths
end