class CSVDecision::Dictionary::Entry

Column dictionary entries.

Constants

ENTRY

Table used to build a column dictionary entry.

INS_TYPES

Input column types.

Attributes

eval[RW]

@return [nil, Boolean] If set to true then this column has procs that

need evaluating, otherwise it only contains constants.
function[RW]

@return [Matchers::Proc, Object] For a column of type set: gives the proc that must be

evaluated to set the default value. If not a proc, then it's some type of constant.
indexed[RW]

@return [Boolean] Returns true if this column is indexed

name[R]

@return [Symbol] Column name.

set_if[R]

@return [nil, true, Symbol] Defined for columns of type :set, nil otherwise.

If true, then default is set unconditionally, otherwise the method symbol
sent to the input hash value that must evaluate to a truthy value.
type[R]

@return [Symbol] Column type.

Public Class Methods

create(name:, type:) click to toggle source

Create a new column dictionary entry defaulting attributes from the column type, which is looked up in the above table.

@param name [Symbol] Column name. @param type [Symbol] Column type. @return [Entry] Column dictionary entry.

# File lib/csv_decision/dictionary.rb, line 51
def self.create(name:, type:)
  entry = ENTRY[type]
  new(name: name,
      eval: entry[:eval],              # Set if the column requires functions evaluated
      type: entry[:type],              # Column type
      set_if: entry[:set_if],          # Set if the column has a conditional default
      indexed: entry[:type] != :guard) # A guard column cannot be indexed.
end
new(name:, type:, eval: nil, set_if: nil, indexed: nil) click to toggle source

@param name (see name) @param type (see type) @param eval (see eval) @param set_if (see set_if) @param indexed (see indexed)

# File lib/csv_decision/dictionary.rb, line 92
def initialize(name:, type:, eval: nil, set_if: nil, indexed: nil)
  @name = name
  @type = type
  @eval = eval
  @set_if = set_if
  @function = nil
  @ins = INS_TYPES.member?(type)
  @indexed = indexed
end

Public Instance Methods

ins?() click to toggle source

@return [Boolean] Return true is this is an input column, false otherwise.

# File lib/csv_decision/dictionary.rb, line 61
def ins?
  @ins
end
to_h() click to toggle source

Convert the object's attributes to a hash.

@return [Hash{Symbol=>[nil, Boolean, Symbol]}]

# File lib/csv_decision/dictionary.rb, line 105
def to_h
  {
    name: @name,
    type: @type,
    eval: @eval,
    set_if: @set_if
  }
end