Class: MusicTodayApiWrapper::Resources::Product

Inherits:
Object
  • Object
show all
Defined in:
lib/resources/product.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uid, name, description, category, price, image = MusicTodayApiWrapper::Resources::Image.new, variants = []) ⇒ Product

rubocop:disable ParameterLists



16
17
18
19
20
21
22
23
24
25
# File 'lib/resources/product.rb', line 16

def initialize(uid, name, description, category, price,
  image = MusicTodayApiWrapper::Resources::Image.new, variants = [])
  @uid = uid
  @name = name
  @description = description
  @category = category
  @price = price
  @image = image
  @variants = variants
end

Instance Attribute Details

#categoryObject

Returns the value of attribute category.



7
8
9
# File 'lib/resources/product.rb', line 7

def category
  @category
end

#descriptionObject

Returns the value of attribute description.



7
8
9
# File 'lib/resources/product.rb', line 7

def description
  @description
end

#imageObject

Returns the value of attribute image.



7
8
9
# File 'lib/resources/product.rb', line 7

def image
  @image
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/resources/product.rb', line 7

def name
  @name
end

#priceObject

Returns the value of attribute price.



7
8
9
# File 'lib/resources/product.rb', line 7

def price
  @price
end

#uidObject

Returns the value of attribute uid.



7
8
9
# File 'lib/resources/product.rb', line 7

def uid
  @uid
end

#variantsObject

Returns the value of attribute variants.



7
8
9
# File 'lib/resources/product.rb', line 7

def variants
  @variants
end

Class Method Details

.from_hash(hash) ⇒ Object

rubocop:disable AbcSize



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/resources/product.rb', line 28

def self.from_hash(hash)
  image = Image.new(hash['imageUrlSmall'],
                    hash['imageUrlMedium'],
                    hash['imageUrlLarge'])

  product = Product.new(hash['id'],
                        hash['name'],
                        hash['lang']['en']['textDesc'],
                        hash['categoryName'],
                        hash['listPrice'],
                        image)

  hash['variants'].each do |variant|
    product.variants << Variant.from_hash(variant)
  end
  product
end