Class: CSVDecision2::Dictionary::Entry Private

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

Column dictionary entries.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, type:, eval: nil, set_if: nil, indexed: nil) ⇒ Entry

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



92
93
94
95
96
97
98
99
100
# File 'lib/csv_decision2/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

Instance Attribute Details

#evalnil, Boolean

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 If set to true then this column has procs that need evaluating, otherwise it only contains constants.

Returns:

  • (nil, Boolean)

    If set to true then this column has procs that need evaluating, otherwise it only contains constants.



76
77
78
# File 'lib/csv_decision2/dictionary.rb', line 76

def eval
  @eval
end

#functionMatchers::Proc, 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.

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

Returns:

  • (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.



85
86
87
# File 'lib/csv_decision2/dictionary.rb', line 85

def function
  @function
end

#indexedBoolean

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 true if this column is indexed

Returns:

  • (Boolean)

    Returns true if this column is indexed



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

def indexed
  @indexed
end

#nameSymbol (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 Column name.

Returns:

  • (Symbol)

    Column name.



66
67
68
# File 'lib/csv_decision2/dictionary.rb', line 66

def name
  @name
end

#set_ifnil, ... (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 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.

Returns:

  • (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.



81
82
83
# File 'lib/csv_decision2/dictionary.rb', line 81

def set_if
  @set_if
end

#typeSymbol (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 Column type.

Returns:

  • (Symbol)

    Column type.



69
70
71
# File 'lib/csv_decision2/dictionary.rb', line 69

def type
  @type
end

Class Method Details

.create(name:, type:) ⇒ Entry

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.

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

Parameters:

  • name (Symbol)

    Column name.

  • type (Symbol)

    Column type.

Returns:

  • (Entry)

    Column dictionary entry.



51
52
53
54
55
56
57
58
# File 'lib/csv_decision2/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

Instance Method Details

#ins?Boolean

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.

Return true is this is an input column, false otherwise.

Returns:

  • (Boolean)

    Return true is this is an input column, false otherwise.



61
62
63
# File 'lib/csv_decision2/dictionary.rb', line 61

def ins?
  @ins
end

#to_hHash{Symbol=>[nil, Boolean, 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.

Convert the object’s attributes to a hash.

Returns:

  • (Hash{Symbol=>[nil, Boolean, Symbol]})


105
106
107
108
109
110
111
112
# File 'lib/csv_decision2/dictionary.rb', line 105

def to_h
  {
    name: @name,
    type: @type,
    eval: @eval,
    set_if: @set_if
  }
end