Class: CSVDecision::Table

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

Overview

Decision table that accepts an input hash and outputs a decision (hash).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTable

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



83
84
85
86
87
88
89
# File 'lib/csv_decision/table.rb', line 83

def initialize
  @paths = []
  @outs_rows = []
  @if_rows = []
  @rows = []
  @scan_rows = []
end

Instance Attribute Details

#columnsCSVDecision::Columns

Returns Dictionary of all input and output columns.

Returns:



31
32
33
# File 'lib/csv_decision/table.rb', line 31

def columns
  @columns
end

#fileFile, ...

CSV file.

Returns:

  • (File, Pathname, nil)

    File path name if decision table was loaded from a



35
36
37
# File 'lib/csv_decision/table.rb', line 35

def file
  @file
end

#if_rowsArray<CSVDecision::ScanRow>

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 Used to implement filtering of final results.

Returns:



65
66
67
# File 'lib/csv_decision/table.rb', line 65

def if_rows
  @if_rows
end

#indexCSVDecision::Index

Returns The index built on one or more input columns.

Returns:



38
39
40
# File 'lib/csv_decision/table.rb', line 38

def index
  @index
end

#optionsHash

Returns All options, explicitly set or defaulted, used to parse the table.

Returns:

  • (Hash)

    All options, explicitly set or defaulted, used to parse the table.



44
45
46
# File 'lib/csv_decision/table.rb', line 44

def options
  @options
end

#outs_functionsObject

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 if the table row has any output functions (planned feature)



48
49
50
# File 'lib/csv_decision/table.rb', line 48

def outs_functions
  @outs_functions
end

#outs_rowsArray<CSVDecision::ScanRow>

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 Used to implement outputting of final results.

Returns:



61
62
63
# File 'lib/csv_decision/table.rb', line 61

def outs_rows
  @outs_rows
end

#pathsCSVDecision::Path

Returns The array of paths built on one or more input columns.

Returns:

  • (CSVDecision::Path)

    The array of paths built on one or more input columns.



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

def paths
  @paths
end

#rowsArray<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 Data rows after parsing.

Returns:

  • (Array<Array>)

    Data rows after parsing.



52
53
54
# File 'lib/csv_decision/table.rb', line 52

def rows
  @rows
end

#scan_rowsArray<CSVDecision::ScanRow>

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 Scanning objects used to implement input matching logic.

Returns:



57
58
59
# File 'lib/csv_decision/table.rb', line 57

def scan_rows
  @scan_rows
end

Instance Method Details

#decide(input) ⇒ {Symbol => Object, Array<Object>}

Note:

Input hash keys may or may not be symbolized.

Make a decision based off an input hash.

Parameters:

  • input (Hash)

    Input hash.

Returns:

  • ({Symbol => Object, Array<Object>})

    Decision hash.



15
16
17
# File 'lib/csv_decision/table.rb', line 15

def decide(input)
  decision(input: input, symbolize_keys: true)
end

#decide!(input) ⇒ {Symbol => Object, Array<Object>}

Note:

Input hash must have its keys symbolized. Input hash will be mutated by any functions that have side effects.

Unsafe version of decide - may mutate the input hash and assumes the input hash is symbolized.

Parameters:

  • input (Hash)

    Input hash.

Returns:

  • ({Symbol => Object, Array<Object>})

    Decision hash.



26
27
28
# File 'lib/csv_decision/table.rb', line 26

def decide!(input)
  decision( input: input, symbolize_keys: false)
end

#each(first = 0, last = @rows.count - 1) ⇒ 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.

Iterate through all data rows of the decision table, with an optional first and last row index given.

Parameters:

  • first (Integer) (defaults to: 0)

    Start row.

  • last (Integer, nil) (defaults to: @rows.count - 1)

    Last row.



73
74
75
76
77
78
79
80
# File 'lib/csv_decision/table.rb', line 73

def each(first = 0, last = @rows.count - 1)
  index = first
  while index <= last
    yield(@rows[index], index)

    index += 1
  end
end