class BusinessCatalyst::CSV::ProductRow
Subclass and call map to set values for columns. You may return arrays for columns that take multiple values, like catalog, and true/false for boolean columns.
nil will always be interpreted as blank.
What method name to use?¶ ↑
Refer to the COLUMNS
constant, but in general use the underscored name of the column, with '?' appended to columns that expect a boolean.
Example¶ ↑
class MyRow < BusinessCatalyst::CSV::ProductRow def initialize(product) @product = product super end map(:product_code) { @product.code } map(:name) { @product.name } map(:catalog) { ["Some", "Accessories"] } map(:enabled?) { @product.active } map(:inventory_control?) { false } # ... (other properties here) end
Later, with a CSV
opened for writing:
csv << MyRow.headers products.each do |product| csv << MyRow.new(product).to_a end
Constants
- COLUMNS
- Header, method, default, transformer
Public Class Methods
columns()
click to toggle source
# File lib/business_catalyst/csv/product_row.rb, line 44 def self.columns COLUMNS end