Class: InstacartApi::Item
- Inherits:
-
Object
- Object
- InstacartApi::Item
- Includes:
- Comparable
- Defined in:
- lib/instacart_api/models/item.rb
Overview
A single product returned by the Items query.
Instacart item ids look like items_<retailerLocationId>-<productId>
(e.g. items_3113-22373938); that full id is what the cart mutation
expects.
Instance Attribute Summary collapse
-
#brand_name ⇒ Object
readonly
Returns the value of attribute brand_name.
-
#full_price ⇒ Object
readonly
Returns the value of attribute full_price.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#price ⇒ Object
readonly
Returns the value of attribute price.
-
#product_id ⇒ Object
readonly
Returns the value of attribute product_id.
-
#quantity_type ⇒ Object
readonly
Returns the value of attribute quantity_type.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#stock_level ⇒ Object
readonly
Returns the value of attribute stock_level.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Compare by price so a list of items can be sorted cheapest-first.
- #available? ⇒ Boolean
-
#initialize(data) ⇒ Item
constructor
A new instance of Item.
Constructor Details
#initialize(data) ⇒ Item
Returns a new instance of Item.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/instacart_api/models/item.rb', line 15 def initialize(data) @id = data["id"] @name = data["name"] @size = data["size"] @product_id = data["productId"] @brand_name = data["brandName"] pricing = data.dig("price", "viewSection") || {} @price = pricing["priceValueString"]&.to_f @full_price = pricing["fullPriceString"] availability = data["availability"] || {} @available = availability["available"] @stock_level = availability["stockLevel"] @quantity_type = (data["quantityAttributes"] || {})["quantityType"] || "each" end |
Instance Attribute Details
#brand_name ⇒ Object (readonly)
Returns the value of attribute brand_name.
12 13 14 |
# File 'lib/instacart_api/models/item.rb', line 12 def brand_name @brand_name end |
#full_price ⇒ Object (readonly)
Returns the value of attribute full_price.
12 13 14 |
# File 'lib/instacart_api/models/item.rb', line 12 def full_price @full_price end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
12 13 14 |
# File 'lib/instacart_api/models/item.rb', line 12 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
12 13 14 |
# File 'lib/instacart_api/models/item.rb', line 12 def name @name end |
#price ⇒ Object (readonly)
Returns the value of attribute price.
12 13 14 |
# File 'lib/instacart_api/models/item.rb', line 12 def price @price end |
#product_id ⇒ Object (readonly)
Returns the value of attribute product_id.
12 13 14 |
# File 'lib/instacart_api/models/item.rb', line 12 def product_id @product_id end |
#quantity_type ⇒ Object (readonly)
Returns the value of attribute quantity_type.
12 13 14 |
# File 'lib/instacart_api/models/item.rb', line 12 def quantity_type @quantity_type end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
12 13 14 |
# File 'lib/instacart_api/models/item.rb', line 12 def size @size end |
#stock_level ⇒ Object (readonly)
Returns the value of attribute stock_level.
12 13 14 |
# File 'lib/instacart_api/models/item.rb', line 12 def stock_level @stock_level end |
Instance Method Details
#<=>(other) ⇒ Object
Compare by price so a list of items can be sorted cheapest-first.
39 40 41 |
# File 'lib/instacart_api/models/item.rb', line 39 def <=>(other) price <=> other.price end |
#available? ⇒ Boolean
34 35 36 |
# File 'lib/instacart_api/models/item.rb', line 34 def available? @available == true end |