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 collapse
- 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/text|in|out/text|out|guard|if|set/nil\?|set/blank\?|set|path) \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:/!?]*"
Class Method Summary collapse
-
.column_name?(column_name) ⇒ Boolean
private
Return true if column name is valid.
-
.parse(table:, matchers:) ⇒ CSVDecision::Columns
private
Parse the header row, and the defaults row if present.
-
.row?(row) ⇒ Boolean
private
Check if the given row contains a recognisable header cell.
-
.strip_empty_columns(rows:) ⇒ Array<Array<String>>
private
Strip empty columns from all data rows.
Class Method Details
.column_name?(column_name) ⇒ 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 if column name is valid.
30 31 32 |
# File 'lib/csv_decision/header.rb', line 30 def self.column_name?(column_name) COLUMN_NAME_RE.match?(column_name) end |
.parse(table:, matchers:) ⇒ CSVDecision::Columns
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.
Parse the header row, and the defaults row if present.
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/csv_decision/header.rb', line 59 def self.parse(table:, matchers:) # Parse the header row table.columns = CSVDecision::Columns.new(table) # Parse the defaults row if present return table.columns if table.columns.defaults.blank? table.columns.defaults = Defaults.parse(columns: table.columns, matchers: matchers.outs, row: table.rows.shift) table.columns end |
.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.
38 39 40 |
# File 'lib/csv_decision/header.rb', line 38 def self.row?(row) row.any? { |cell| COLUMN_TYPE.match?(cell) } 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.
47 48 49 50 51 52 53 |
# File 'lib/csv_decision/header.rb', line 47 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 |