class Distributator
REMINDER: An empty cell can return nil or '' #
Public Class Methods
new(data, options = Hash.new)
click to toggle source
Calls superclass method
# File lib/distributator.rb, line 10 def initialize(data, options = Hash.new) options.merge!({ headers: true, header_converters: [self.class.rename_header, *options[:header_converters]] }) super(data, options) end
rename_header()
click to toggle source
# File lib/distributator.rb, line 17 def self.rename_header ->(header) do case header when /\A['"]?estimated_availability_date['"]?\Z/i 'available_on' when /\A['"]?image_(\w+)_(\d+)['"]?\Z/ # TODO: should this have a default value? lookup = { 'reference' => 'url', 'name' => 'title' } "images.#{$2}.#{lookup[$1]}" when /\A['"]?upc['"]?\Z/i 'id' when /\A['"]?cost['"]?\Z/i 'cost_price' when /\A['"]?product_title['"]?\Z/i 'name' else header.gsub(/'|"/, '') end end end