Module: CSVUtils::CSVRow

Defined in:
lib/csv_utils/csv_row.rb

Overview

Mixin that declares how an object turns into a CSV row, for use with CSVReport. Columns are inherited by subclasses.

Examples:

class UserCSVRow < User
  include CSVUtils::CSVRow

  csv_column :id, header: 'ID'
  csv_column :name
  csv_column(:email) { email.downcase }
end

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ 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.

Parameters:

  • base (Class)


21
22
23
24
# File 'lib/csv_utils/csv_row.rb', line 21

def self.included(base)
  base.extend InheritanceHelper::Methods
  base.extend ClassMethods
end

Instance Method Details

#csv_headers ⇒ Array<String>

Returns the header of each column.

Returns:

  • (Array<String>) —

    the header of each column



75
76
77
# File 'lib/csv_utils/csv_row.rb', line 75

def csv_headers
  self.class.csv_headers
end

#csv_row ⇒ Array Also known as: to_a

The value of each column.

Returns:

  • (Array)


69
70
71
# File 'lib/csv_utils/csv_row.rb', line 69

def csv_row
  self.class.csv_columns.values.map { |column_options| csv_column_value(column_options) }
end