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.
-
#last_updated ⇒ Object
readonly
Returns the value of attribute last_updated.
-
#offer_id ⇒ Object
readonly
Returns the value of attribute offer_id.
-
#price ⇒ Object
readonly
Returns the value of attribute price.
-
#retailer ⇒ Object
readonly
Returns the value of attribute retailer.
-
#shipping ⇒ Object
readonly
Returns the value of attribute shipping.
-
#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.
- #limited_stock? ⇒ Boolean
- #new_condition? ⇒ Boolean
- #out_of_stock? ⇒ Boolean
- #refurbished_condition? ⇒ Boolean
- #to_h ⇒ Object
- #used_condition? ⇒ Boolean
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
#availability ⇒ Object (readonly)
Returns the value of attribute availability.
65 66 67 |
# File 'lib/shopsavvy_data_api/models.rb', line 65 def availability @availability end |
#condition ⇒ Object (readonly)
Returns the value of attribute condition.
65 66 67 |
# File 'lib/shopsavvy_data_api/models.rb', line 65 def condition @condition end |
#currency ⇒ Object (readonly)
Returns the value of attribute currency.
65 66 67 |
# File 'lib/shopsavvy_data_api/models.rb', line 65 def currency @currency end |
#last_updated ⇒ Object (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_id ⇒ Object (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 |
#price ⇒ Object (readonly)
Returns the value of attribute price.
65 66 67 |
# File 'lib/shopsavvy_data_api/models.rb', line 65 def price @price end |
#retailer ⇒ Object (readonly)
Returns the value of attribute retailer.
65 66 67 |
# File 'lib/shopsavvy_data_api/models.rb', line 65 def retailer @retailer end |
#shipping ⇒ Object (readonly)
Returns the value of attribute shipping.
65 66 67 |
# File 'lib/shopsavvy_data_api/models.rb', line 65 def shipping @shipping end |
#url ⇒ Object (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
94 95 96 |
# File 'lib/shopsavvy_data_api/models.rb', line 94 def in_stock? availability == "in_stock" end |
#limited_stock? ⇒ Boolean
102 103 104 |
# File 'lib/shopsavvy_data_api/models.rb', line 102 def limited_stock? availability == "limited_stock" end |
#new_condition? ⇒ Boolean
106 107 108 |
# File 'lib/shopsavvy_data_api/models.rb', line 106 def new_condition? condition == "new" end |
#out_of_stock? ⇒ 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
114 115 116 |
# File 'lib/shopsavvy_data_api/models.rb', line 114 def refurbished_condition? condition == "refurbished" end |
#to_h ⇒ Object
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
110 111 112 |
# File 'lib/shopsavvy_data_api/models.rb', line 110 def used_condition? condition == "used" end |