Class: BusinessCatalyst::CSV::ProductAttributesTransformer
- Inherits:
-
Transformer
- Object
- Transformer
- BusinessCatalyst::CSV::ProductAttributesTransformer
- Defined in:
- lib/business_catalyst/csv/transformers/product_attributes_transformer.rb
Overview
Example: Chain*|5|N:Rope Chain||US/0,Box Chain||US/5,Snake Chain||US/5;Length*|5|N:16 inch||US/0,18 inch||US/0,20 inch||US/0,24 inch||US/0
Name1REQ|display_as|keep_stock:Option1.name|Option1.image|Option1.price,Option2.name|…;Name2…
Instance Attribute Summary
Attributes inherited from Transformer
Instance Method Summary collapse
Methods inherited from Transformer
Constructor Details
This class inherits a constructor from BusinessCatalyst::CSV::Transformer
Instance Method Details
#attributes ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/business_catalyst/csv/transformers/product_attributes_transformer.rb', line 35 def attributes if input.kind_of?(Array) input.compact else [input].compact end end |
#transform ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/business_catalyst/csv/transformers/product_attributes_transformer.rb', line 10 def transform if input.kind_of?(String) input elsif input attributes.map {|attribute| name = BusinessCatalyst.sanitize_catalog_name(attribute.name) required = attribute.required ? '*' : '' display_as = attribute.display_as.to_i keep_stock = BooleanTransformer.transform(attribute.keep_stock) text = ["#{name}#{required}", display_as, keep_stock].join("|") text << ":" text << attribute..map {|option| name = BusinessCatalyst.sanitize_catalog_name(option.name.to_s) image = option.image.to_s.strip price = CurrencyTransformer.transform(option.price) [name, image, price].join("|") }.join(",") text }.join(";") end end |