Class: ShopsavvyDataApi::ProductWithOffers

Inherits:
ProductDetails show all
Defined in:
lib/shopsavvy_data_api/models.rb

Overview

Product with nested offers (returned by offers endpoint)

Instance Attribute Summary collapse

Attributes inherited from ProductDetails

#amazon, #attributes, #barcode, #brand, #categories, #category, #color, #description, #identifiers, #images, #keywords, #model, #mpn, #rating, #score, #shopsavvy, #slug, #title, #title_short

Instance Method Summary collapse

Methods inherited from ProductDetails

#asin, #image_url, #name, #product_id

Constructor Details

#initialize(data) ⇒ ProductWithOffers

Returns a new instance of ProductWithOffers.



115
116
117
118
# File 'lib/shopsavvy_data_api/models.rb', line 115

def initialize(data)
  super(data)
  @offers = (data["offers"] || []).map { |offer| Offer.new(offer) }
end

Instance Attribute Details

#offersObject (readonly)

Returns the value of attribute offers.



113
114
115
# File 'lib/shopsavvy_data_api/models.rb', line 113

def offers
  @offers
end

Instance Method Details

#to_hObject



120
121
122
# File 'lib/shopsavvy_data_api/models.rb', line 120

def to_h
  super.merge(offers: offers.map(&:to_h))
end