Module: CSVDecision::Header Private

Defined in:
lib/csv_decision/header.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 the CSV file's header row. These methods are only required at table load time.

Constant Summary

COLUMN_TYPE =

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

Column types recognised in the header row.

%r{
  \A(?<type>in|out|in/text|out/text|guard|if)
  \s*:\s*(?<name>\S?.*)\z
}xi
COLUMN_NAME =

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

Regular expression string for a column name. More lenient than a Ruby method name - note any spaces will have been replaced with underscores.

"\\w[\\w:/!?]*"
COLUMN_NAME_RE =

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

Regular expression for matching a column name.

Matchers.regexp(Header::COLUMN_NAME)

Class Method Summary collapse

Class Method Details

.row?(row) ⇒ 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.

Check if the given row contains a recognisable header cell.

Parameters:

  • row (Array<String>)

    Header row.

Returns:

  • (Boolean)

    Return true if the row looks like a header.



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

def self.row?(row)
  row.any? { |cell| cell.match(COLUMN_TYPE) }
end

.strip_empty_columns(rows:) ⇒ Array<Array<String>>

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.

Strip empty columns from all data rows.

Parameters:

  • rows (Array<Array<String>>)

    Data rows.

Returns:

  • (Array<Array<String>>)

    Data array after removing any empty columns and the header row.



44
45
46
47
48
49
50
# File 'lib/csv_decision/header.rb', line 44

def self.strip_empty_columns(rows:)
  empty_cols = empty_columns?(row: rows.first)
  Data.strip_columns(data: rows, empty_columns: empty_cols) if empty_cols

  # Remove header row from the data array.
  rows.shift
end