Class: CSVDecision2::Index Private

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

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

Parameters:



79
80
81
82
83
84
85
86
# File 'lib/csv_decision2/index.rb', line 79

def initialize(table:, columns:)
  @columns = columns
  @hash = {}

  build(table)

  freeze
end

Instance Attribute Details

#columnsArray<Integer> (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 Array of column indices.

Returns:

  • (Array<Integer>)

    Array of column indices



75
76
77
# File 'lib/csv_decision2/index.rb', line 75

def columns
  @columns
end

#hashHash (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.



72
73
74
# File 'lib/csv_decision2/index.rb', line 72

def hash
  @hash
end

Class Method Details

.build(table:) ⇒ CSVDecision2::Index

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 on the designated number of input columns.

Parameters:

Returns:



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/csv_decision2/index.rb', line 16

def self.build(table:)
  # Do we even have an index?
  key_cols = index_columns(columns: table.columns.ins)
  return if key_cols.empty?

  table.index = Index.new(table: table, columns: key_cols)

  # Indexed columns do not need to be scanned
  trim_scan_rows(scan_rows: table.scan_rows, index_columns: table.index.columns)

  table
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 index key value.

Parameters:

  • current_value (Integer, Array)

    Current index key value.

  • index (Integer)

    Array row index to be included in the table index entry.

Returns:

  • (Integer, Array)

    New index key value.



32
33
34
35
36
37
38
# File 'lib/csv_decision2/index.rb', line 32

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

  array_value(current_value, index)

  current_value
end