Class: CSVDecision::Paths Private

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

API:

  • private

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:

  • Decision table.

  • Array of column indexes to be indexed.

API:

  • private



45
46
47
48
49
50
51
52
# File 'lib/csv_decision/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:

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

API:

  • private



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

def paths
  @paths
end

Class Method Details

.scan(table:) ⇒ CSVDecision::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:

  • Decision table being indexed.

Returns:

  • The built index of paths.

API:

  • private



16
17
18
19
20
21
22
# File 'lib/csv_decision/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:

  • Cell value for the path: column.

Returns:

  • Non-empty string converted to a symbol.

API:

  • private



36
37
38
# File 'lib/csv_decision/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 path value.

  • Array row index to be included in the path entry.

Returns:

  • New path key value.

API:

  • private



27
28
29
30
31
32
# File 'lib/csv_decision/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