class CsvSerializer::Definition

Represents definition of csv columns.

Attributes

records[R]

Public Class Methods

build(array, hash, records) click to toggle source
# File lib/csv_serializer/definition.rb, line 6
def self.build(array, hash, records)
  if array.blank? && hash.blank?
    AllColumn.new(records)
  elsif array.blank?
    FunctionHash.new(records, hash)
  elsif array.all?(Symbol)
    SymbolArray.new(records, array)
  else
    FunctionArray.new(records, array)
  end
end
new(records, array_or_hash = nil) click to toggle source
# File lib/csv_serializer/definition.rb, line 18
def initialize(records, array_or_hash = nil)
  @records = records
  @array_or_hash = array_or_hash
end

Public Instance Methods

definitions() click to toggle source
# File lib/csv_serializer/definition.rb, line 23
def definitions
  @array_or_hash
end
header() click to toggle source
# File lib/csv_serializer/definition.rb, line 35
def header
  column_names.map { records.human_attribute_name(_1) }
end
serializer() click to toggle source
# File lib/csv_serializer/definition.rb, line 27
def serializer
  Serializer.new(self)
end
target_records() click to toggle source
# File lib/csv_serializer/definition.rb, line 31
def target_records
  records.all
end