Class: ShopsavvyDataApi::Offer
- Inherits:
-
Object
- Object
- ShopsavvyDataApi::Offer
- Defined in:
- lib/shopsavvy_data_api/models.rb
Overview
Product offer from a retailer
Direct Known Subclasses
Instance Attribute Summary collapse
-
#availability ⇒ Object
readonly
Returns the value of attribute availability.
-
#condition ⇒ Object
readonly
Returns the value of attribute condition.
-
#currency ⇒ Object
readonly
Returns the value of attribute currency.
-
#history ⇒ Object
readonly
Returns the value of attribute history.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#price ⇒ Object
readonly
Returns the value of attribute price.
-
#retailer ⇒ Object
readonly
Returns the value of attribute retailer.
-
#seller ⇒ Object
readonly
Returns the value of attribute seller.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
-
#URL ⇒ Object
readonly
Returns the value of attribute URL.
Instance Method Summary collapse
- #in_stock? ⇒ Boolean
-
#initialize(data) ⇒ Offer
constructor
A new instance of Offer.
-
#last_updated ⇒ Object
deprecated
Deprecated.
Use ‘timestamp` instead
- #limited_stock? ⇒ Boolean
- #new_condition? ⇒ Boolean
-
#offer_id ⇒ Object
deprecated
Deprecated.
Use ‘id` instead
- #out_of_stock? ⇒ Boolean
- #refurbished_condition? ⇒ Boolean
- #to_h ⇒ Object
-
#url ⇒ Object
deprecated
Deprecated.
Use ‘URL` instead
- #used_condition? ⇒ Boolean
Constructor Details
#initialize(data) ⇒ Offer
Returns a new instance of Offer.
130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/shopsavvy_data_api/models.rb', line 130 def initialize(data) @id = data["id"] @retailer = data["retailer"] @price = data["price"]&.to_f @currency = data["currency"] || "USD" @availability = data["availability"] @condition = data["condition"] @URL = data["URL"] @seller = data["seller"] @timestamp = data["timestamp"] @history = (data["history"] || []).map { |entry| PriceHistoryEntry.new(entry) } end |
Instance Attribute Details
#availability ⇒ Object (readonly)
Returns the value of attribute availability.
127 128 129 |
# File 'lib/shopsavvy_data_api/models.rb', line 127 def availability @availability end |
#condition ⇒ Object (readonly)
Returns the value of attribute condition.
127 128 129 |
# File 'lib/shopsavvy_data_api/models.rb', line 127 def condition @condition end |
#currency ⇒ Object (readonly)
Returns the value of attribute currency.
127 128 129 |
# File 'lib/shopsavvy_data_api/models.rb', line 127 def currency @currency end |
#history ⇒ Object (readonly)
Returns the value of attribute history.
127 128 129 |
# File 'lib/shopsavvy_data_api/models.rb', line 127 def history @history end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
127 128 129 |
# File 'lib/shopsavvy_data_api/models.rb', line 127 def id @id end |
#price ⇒ Object (readonly)
Returns the value of attribute price.
127 128 129 |
# File 'lib/shopsavvy_data_api/models.rb', line 127 def price @price end |
#retailer ⇒ Object (readonly)
Returns the value of attribute retailer.
127 128 129 |
# File 'lib/shopsavvy_data_api/models.rb', line 127 def retailer @retailer end |
#seller ⇒ Object (readonly)
Returns the value of attribute seller.
127 128 129 |
# File 'lib/shopsavvy_data_api/models.rb', line 127 def seller @seller end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
127 128 129 |
# File 'lib/shopsavvy_data_api/models.rb', line 127 def @timestamp end |
#URL ⇒ Object (readonly)
Returns the value of attribute URL.
127 128 129 |
# File 'lib/shopsavvy_data_api/models.rb', line 127 def URL @URL end |
Instance Method Details
#in_stock? ⇒ Boolean
173 174 175 |
# File 'lib/shopsavvy_data_api/models.rb', line 173 def in_stock? availability == "in_stock" end |
#last_updated ⇒ Object
Use ‘timestamp` instead
154 155 156 |
# File 'lib/shopsavvy_data_api/models.rb', line 154 def last_updated end |
#limited_stock? ⇒ Boolean
181 182 183 |
# File 'lib/shopsavvy_data_api/models.rb', line 181 def limited_stock? availability == "limited_stock" end |
#new_condition? ⇒ Boolean
185 186 187 |
# File 'lib/shopsavvy_data_api/models.rb', line 185 def new_condition? condition == "new" end |
#offer_id ⇒ Object
Use ‘id` instead
144 145 146 |
# File 'lib/shopsavvy_data_api/models.rb', line 144 def offer_id id end |
#out_of_stock? ⇒ Boolean
177 178 179 |
# File 'lib/shopsavvy_data_api/models.rb', line 177 def out_of_stock? availability == "out_of_stock" end |
#refurbished_condition? ⇒ Boolean
193 194 195 |
# File 'lib/shopsavvy_data_api/models.rb', line 193 def refurbished_condition? condition == "refurbished" end |
#to_h ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/shopsavvy_data_api/models.rb', line 158 def to_h { id: id, retailer: retailer, price: price, currency: currency, availability: availability, condition: condition, URL: URL, seller: seller, timestamp: , history: history.map(&:to_h) } end |
#url ⇒ Object
Use ‘URL` instead
149 150 151 |
# File 'lib/shopsavvy_data_api/models.rb', line 149 def url URL end |
#used_condition? ⇒ Boolean
189 190 191 |
# File 'lib/shopsavvy_data_api/models.rb', line 189 def used_condition? condition == "used" end |