Module: CSVDecision2::Validate Private

Defined in:
lib/csv_decision2/validate.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Parse and validate the column names in the header row. These methods are only required at table load time.

Class Method Summary collapse

Class Method Details

.column(cell:, index:) ⇒ Array<(Symbol, 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.

Validate a column header cell and return its type and name.

Parameters:

  • cell (String)

    Header cell.

  • index (Integer)

    The header column’s index.

Returns:

  • (Array<(Symbol, Symbol)>)

    Column type and column name symbols.



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/csv_decision2/validate.rb', line 21

def self.column(cell:, index:)
  match = Header::COLUMN_TYPE.match(cell)
  raise CellValidationError, 'column name is not well formed' unless match

  column_type = match['type']&.downcase&.to_sym
  column_name = column_name(type: column_type, name: match['name'], index: index)

  [column_type, column_name]
rescue CellValidationError => exp
  raise CellValidationError, "header column '#{cell}' is not valid as the #{exp.message}"
end

.name(columns:, name:, out:) ⇒ void

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.

This method returns an undefined value.

Validate the column name against the dictionary of column names.

Parameters:

  • columns (Symbol=>[false, Integer])

    Column name dictionary.

  • name (Symbol)

    Column name.

  • out (false, Integer)

    False if an input column, otherwise the column index of the output column.

Raises:



41
42
43
44
45
46
# File 'lib/csv_decision2/validate.rb', line 41

def self.name(columns:, name:, out:)
  return unless (in_out = columns[name])

  return validate_out_name(in_out: in_out, name: name) if out
  validate_in_name(in_out: in_out, name: name)
end