module DSCO_Table
Public Instance Methods
convert_attributes()
click to toggle source
# File lib/distributator.rb, line 43 def convert_attributes each do |row| attr_indices.each do |index| attr_name = "attribute_name_#{index}" attr_val = "attribute_value_#{index}" row["properties.#{row[attr_name]}"] = row[attr_val] end end attr_indices.each do |index| delete("attribute_name_#{index}") delete("attribute_value_#{index}") end; return nil end
convert_price()
click to toggle source
# File lib/distributator.rb, line 58 def convert_price each do |row| map, msrp = row['map'], row['msrp'] price = map unless map.nil? || map.to_f.zero? # implies #empty? price ||= msrp raise PriceError if price.to_f.zero? row['price'] = price end delete('msrp'); delete('map') end
convert_taxons()
click to toggle source
# File lib/distributator.rb, line 71 def convert_taxons each do |row| row['category'].split('|').each_with_index do |taxon, i| # WARNING: Jenson only uses one taxon group per product # So this code only handles one taxon group. row["taxons.0.#{i}"] = taxon end end delete('category') end
make_permalinks()
click to toggle source
# File lib/distributator.rb, line 82 def make_permalinks each do |row| row['permalink'] = row['name'].parameterize end end
normalize_available_on()
click to toggle source
# File lib/distributator.rb, line 88 def normalize_available_on each do |row| if row['available_on'].nil? || row['available_on'].empty? row['available_on'] = DateTime.now.iso8601 end end end
Private Instance Methods
attr_indices()
click to toggle source
# File lib/distributator.rb, line 97 def attr_indices headers.map { |h| h.match(/attribute_name_(\d+)/); $1 }.compact end