Module: CSVUtils::CSVRow::ClassMethods
- Defined in:
- lib/csv_utils/csv_row.rb
Overview
Class level DSL for declaring columns.
Instance Method Summary collapse
-
#csv_column(header, options = {}) { ... } ⇒ void
Declares a column.
-
#csv_columns ⇒ Hash{Symbol => Hash}
Declared columns, keyed by name, in declaration order.
-
#csv_headers ⇒ Array<String>
The header of each column.
Instance Method Details
#csv_column(header, options = {}) { ... } ⇒ void
This method returns an undefined value.
Declares a column.
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/csv_utils/csv_row.rb', line 42 def csv_column(header, = {}, &block) = .dup [:header] ||= header.to_s if block [:proc] = block elsif [:proc].nil? [:method] ||= header end add_value_to_class_method(:csv_columns, header => ) end |
#csv_columns ⇒ Hash{Symbol => Hash}
Declared columns, keyed by name, in declaration order.
30 31 32 |
# File 'lib/csv_utils/csv_row.rb', line 30 def csv_columns {} end |
#csv_headers ⇒ Array<String>
Returns the header of each column.
56 57 58 |
# File 'lib/csv_utils/csv_row.rb', line 56 def csv_headers csv_columns.values.map { || csv_column_header() } end |