Class: ShopsavvyDataApi::Offer

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

Overview

Product offer from a retailer

Direct Known Subclasses

OfferWithHistory

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Offer

Returns a new instance of Offer.



68
69
70
71
72
73
74
75
76
77
78
# File 'lib/shopsavvy_data_api/models.rb', line 68

def initialize(data)
  @offer_id = data["offer_id"]
  @retailer = data["retailer"]
  @price = data["price"].to_f
  @currency = data["currency"] || "USD"
  @availability = data["availability"]
  @condition = data["condition"]
  @url = data["url"]
  @shipping = data["shipping"]&.to_f
  @last_updated = data["last_updated"]
end

Instance Attribute Details

#availabilityObject (readonly)

Returns the value of attribute availability.



65
66
67
# File 'lib/shopsavvy_data_api/models.rb', line 65

def availability
  @availability
end

#conditionObject (readonly)

Returns the value of attribute condition.



65
66
67
# File 'lib/shopsavvy_data_api/models.rb', line 65

def condition
  @condition
end

#currencyObject (readonly)

Returns the value of attribute currency.



65
66
67
# File 'lib/shopsavvy_data_api/models.rb', line 65

def currency
  @currency
end

#last_updatedObject (readonly)

Returns the value of attribute last_updated.



65
66
67
# File 'lib/shopsavvy_data_api/models.rb', line 65

def last_updated
  @last_updated
end

#offer_idObject (readonly)

Returns the value of attribute offer_id.



65
66
67
# File 'lib/shopsavvy_data_api/models.rb', line 65

def offer_id
  @offer_id
end

#priceObject (readonly)

Returns the value of attribute price.



65
66
67
# File 'lib/shopsavvy_data_api/models.rb', line 65

def price
  @price
end

#retailerObject (readonly)

Returns the value of attribute retailer.



65
66
67
# File 'lib/shopsavvy_data_api/models.rb', line 65

def retailer
  @retailer
end

#shippingObject (readonly)

Returns the value of attribute shipping.



65
66
67
# File 'lib/shopsavvy_data_api/models.rb', line 65

def shipping
  @shipping
end

#urlObject (readonly)

Returns the value of attribute url.



65
66
67
# File 'lib/shopsavvy_data_api/models.rb', line 65

def url
  @url
end

Instance Method Details

#in_stock?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/shopsavvy_data_api/models.rb', line 94

def in_stock?
  availability == "in_stock"
end

#limited_stock?Boolean

Returns:

  • (Boolean)


102
103
104
# File 'lib/shopsavvy_data_api/models.rb', line 102

def limited_stock?
  availability == "limited_stock"
end

#new_condition?Boolean

Returns:

  • (Boolean)


106
107
108
# File 'lib/shopsavvy_data_api/models.rb', line 106

def new_condition?
  condition == "new"
end

#out_of_stock?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/shopsavvy_data_api/models.rb', line 98

def out_of_stock?
  availability == "out_of_stock"
end

#refurbished_condition?Boolean

Returns:

  • (Boolean)


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

def refurbished_condition?
  condition == "refurbished"
end

#to_hObject



80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/shopsavvy_data_api/models.rb', line 80

def to_h
  {
    offer_id: offer_id,
    retailer: retailer,
    price: price,
    currency: currency,
    availability: availability,
    condition: condition,
    url: url,
    shipping: shipping,
    last_updated: last_updated
  }
end

#used_condition?Boolean

Returns:

  • (Boolean)


110
111
112
# File 'lib/shopsavvy_data_api/models.rb', line 110

def used_condition?
  condition == "used"
end