class Epages::Product
Constants
- KEYS
Public Class Methods
# File lib/epages/product.rb, line 17 def initialize(data) parse_attribute_as_array_of(:images, data.delete(:images), Epages::Image) parse_attribute_as_array_of(:links, data.delete(:links), Epages::Link) parse_attribute_as(:price_info, data.delete(:priceInfo), Epages::PriceInfo) parse_attributes(data) end
Public Instance Methods
compare the product with another product. 2 products are considered equals if both has the same id, the same name and the same product_number
# File lib/epages/product.rb, line 26 def ==(other) return false unless other.is_a? Epages::Product product_id == other.product_id && name == other.name && product_number == other.product_number end
add an image to the slideshow
@param image [String]
# File lib/epages/product.rb, line 59 def add_slideshow_image(image) product_add_slideshow_image(self, image) end
returns the categories of the product
# File lib/epages/product.rb, line 93 def categories product_categories(self) if link?('categories') end
returns the list of custom_attributes
of the product
# File lib/epages/product.rb, line 88 def custom_attributes product_custom_attributes(self) if link?('custom-attributes') end
remove the image passed from the slideshow and return the new slideshow
@param image [String]
# File lib/epages/product.rb, line 66 def delete_slideshow_image(image) product_delete_slideshow_image(self, image) end
returns the host of the shop that belongs to the product
# File lib/epages/product.rb, line 37 def host URI.parse(sf_url).host end
returns true if [name] is included in the list of links
# File lib/epages/product.rb, line 47 def link?(name) links_title.include? name end
returns the list of links
# File lib/epages/product.rb, line 42 def links_title links.collect(&:rel) end
returns the lowest price of all the variations of the product
# File lib/epages/product.rb, line 98 def lowest_price product_lowest_price(self) if link?('lowest-price') end
returns the name of the shop that belongs the product
# File lib/epages/product.rb, line 32 def shop_name sf_url[%r{epages\/(\w+)}, 1] end
returns the list of slides of the product
# File lib/epages/product.rb, line 52 def slideshow product_slideshow(self) if link?('slideshow') end
returns an array containing the slideshow sequence
# File lib/epages/product.rb, line 71 def slideshow_sequence product_slideshow_sequence(self) end
return a hash with productId and quantity. This format is used for the line_items of Cart
# File lib/epages/product.rb, line 103 def to_line_item(quantity = 1) {productId: product_id, quantity: quantity} end
updates the order of the sequence with the data passed as parameter
@param data [Array]
# File lib/epages/product.rb, line 78 def update_slideshow_sequence(data) product_update_slideshow_sequence(self, data) end
returns the list of variations of the product
# File lib/epages/product.rb, line 83 def variations product_variations(self) if link?('variations') end