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:



167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/csv_decision/columns.rb', line 167

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



128
129
130
# File 'lib/csv_decision/columns.rb', line 128

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



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

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.



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

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:



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

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.



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

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:



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

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:



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

def outs
  @dictionary&.outs
end