class CsvShaper::Header
Header
Handles creating and mapping of the headers Examples: “‘ # assign the headers from the attributes of a class csv.headers User
# assigns headers normally csv.headers :name, :age, :location
# pass a block csv.headers do |csv|
csv.columns :name, :age, :location csv.mappings name: 'Full name, location: 'Region'
end “‘
Attributes
Public Class Methods
Source
# File lib/csv_shaper/header.rb, line 21 def initialize(*args) @mappings = {} @columns = [] @inflector = CsvShaper::Shaper.config.options[:header_inflector] if block_given? yield self elsif args.any? if (@klass = args.first.respond_to?(:attribute_names) && args.first) columns(*@klass.attribute_names) else columns(*args) end end end
Public Instance Methods
Source
# File lib/csv_shaper/header.rb, line 47 def columns(*args) @columns = @columns | args.map(&:to_sym) end
Public: serves as the getter and setter for the Array of Symbol column names. Union join the existing column names with those passed Example: “‘ header.columns :name, :age, :location “` `args` - Array of Symbol arguments passed
Returns as Array of Symbols