Class: Scalablepress::Product
- Inherits:
-
Object
- Object
- Scalablepress::Product
- Defined in:
- lib/scalablepress/resources/product.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#product_id ⇒ Object
readonly
Returns the value of attribute product_id.
Class Method Summary collapse
Instance Method Summary collapse
- #colors ⇒ Object
- #images_for_color(color) ⇒ Object
-
#initialize(params) ⇒ Product
constructor
A new instance of Product.
- #product_info ⇒ Object
Constructor Details
#initialize(params) ⇒ Product
Returns a new instance of Product.
6 7 8 9 |
# File 'lib/scalablepress/resources/product.rb', line 6 def initialize(params) @name = params["name"] @product_id = params["id"] end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/scalablepress/resources/product.rb', line 3 def name @name end |
#product_id ⇒ Object (readonly)
Returns the value of attribute product_id.
4 5 6 |
# File 'lib/scalablepress/resources/product.rb', line 4 def product_id @product_id end |
Class Method Details
Instance Method Details
#colors ⇒ Object
16 17 18 19 |
# File 'lib/scalablepress/resources/product.rb', line 16 def colors @colors = product_info["colors"] @colors.map {|c| c["name"] } end |
#images_for_color(color) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/scalablepress/resources/product.rb', line 21 def images_for_color(color) matched_color = product_info["colors"].select {|c| c["name"] == color }.first raise "#{color} is invalid color selection for #{colors.join(", ")}" unless matched_color images = matched_color["images"] raise "Found no images for #{color}!" unless images.any? images.map {|x| x["url"] } end |