class Scalablepress::Product

Attributes

name[R]
product_id[R]

Public Class Methods

all() click to toggle source
# File lib/scalablepress/resources/product.rb, line 29
def self.all
  Category.all.map {|c| c.products }.flatten
end
new(params) click to toggle source
# File lib/scalablepress/resources/product.rb, line 6
def initialize(params)
  @name = params["name"]
  @product_id = params["id"]
end

Public Instance Methods

colors() click to toggle source
# File lib/scalablepress/resources/product.rb, line 16
def colors
  @colors = product_info["colors"]
  @colors.map {|c| c["name"] }
end
images_for_color(color) click to toggle source
# 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
product_info() click to toggle source
# File lib/scalablepress/resources/product.rb, line 11
def product_info
  return @product_info if @product_info
  @product_info = API.get("products/#{@product_id}")
end