Module: CSVDecision::Header
- Defined in:
- lib/csv_decision/header.rb
Overview
Parse the CSV file's header row. These methods are only required at table load time.
Constant Summary
- COLUMN_TYPE =
Column types recognise din the header row.
%r{ \A(?<type>in|out|in/text|out/text) \s*:\s*(?<name>\S?.*)\z }xi
- COLUMN_NAME =
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 =
Column name regular expression.
Matchers.regexp(COLUMN_NAME)
Class Method Summary collapse
-
.dictionary(row:) ⇒ Hash<Hash>
Classify and build a dictionary of all input and output columns.
-
.row?(row) ⇒ Boolean
Check if the given row contains a recognisable header cell.
-
.strip_empty_columns(rows:) ⇒ Array<Array<String>>
Strip empty columns from all data rows.
Class Method Details
.dictionary(row:) ⇒ Hash<Hash>
Classify and build a dictionary of all input and output columns.
57 58 59 60 61 62 63 64 65 |
# File 'lib/csv_decision/header.rb', line 57 def self.dictionary(row:) dictionary = Columns::Dictionary.new row.each_with_index do |cell, index| dictionary = parse_cell(cell: cell, index: index, dictionary: dictionary) end dictionary end |
.row?(row) ⇒ Boolean
Check if the given row contains a recognisable header cell.
36 37 38 |
# File 'lib/csv_decision/header.rb', line 36 def self.row?(row) row.find { |cell| cell.match(COLUMN_TYPE) } end |
.strip_empty_columns(rows:) ⇒ Array<Array<String>>
Strip empty columns from all data rows.
45 46 47 48 49 50 51 |
# File 'lib/csv_decision/header.rb', line 45 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 |