Class: CSVDecision2::Paths Private

Inherits:
Object
  • Object
show all
Defined in:
lib/csv_decision2/paths.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.

Build an index for a decision table with one or more input columns designated as keys

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table:, columns:) ⇒ Paths

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 Paths.

Parameters:



45
46
47
48
49
50
51
52
# File 'lib/csv_decision2/paths.rb', line 45

def initialize(table:, columns:)
  @paths = []
  @columns = columns

  build(table)

  freeze
end

Instance Attribute Details

#pathsHash (readonly)

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 The index hash mapping in input values to one or more data array row indexes.

Returns:

  • (Hash)

    The index hash mapping in input values to one or more data array row indexes.



41
42
43
# File 'lib/csv_decision2/paths.rb', line 41

def paths
  @paths
end

Class Method Details

.scan(table:) ⇒ CSVDecision2::Paths

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.

Build the index of paths

Parameters:

Returns:



16
17
18
19
20
21
22
# File 'lib/csv_decision2/paths.rb', line 16

def self.scan(table:)
  # Do we even have paths?
  columns = table.columns.paths.keys
  return [] if columns.empty?

  table.paths = Paths.new(table: table, columns: columns).paths
end

.symbol(value) ⇒ nil, 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 Non-empty string converted to a symbol.

Parameters:

  • value (String)

    Cell value for the path: column.

Returns:

  • (nil, Symbol)

    Non-empty string converted to a symbol.



36
37
38
# File 'lib/csv_decision2/paths.rb', line 36

def self.symbol(value)
  value.blank? ? nil : value.to_sym
end

.value(current_value, index) ⇒ Integer, Array

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 New path key value.

Parameters:

  • current_value (Integer, Array)

    Current path value.

  • index (Integer)

    Array row index to be included in the path entry.

Returns:

  • (Integer, Array)

    New path key value.



27
28
29
30
31
32
# File 'lib/csv_decision2/paths.rb', line 27

def self.value(current_value, index)
  return [current_value, index] if current_value.is_a?(Integer)

  current_value[-1] = index
  current_value
end