Class: Cornerstore::Variant
- Inherits:
-
Model::Base
- Object
- Model::Base
- Cornerstore::Variant
- Defined in:
- lib/cornerstore/api/variant.rb
Defined Under Namespace
Classes: Resource
Instance Attribute Summary collapse
-
#differentiating_properties ⇒ Object
Returns the value of attribute differentiating_properties.
-
#offer ⇒ Object
(also: #offer?)
Returns the value of attribute offer.
-
#order_number ⇒ Object
Returns the value of attribute order_number.
-
#oversell ⇒ Object
Returns the value of attribute oversell.
-
#price ⇒ Object
Returns the value of attribute price.
-
#properties ⇒ Object
Returns the value of attribute properties.
-
#qty_in_stock ⇒ Object
Returns the value of attribute qty_in_stock.
-
#qty_reserved ⇒ Object
Returns the value of attribute qty_reserved.
-
#unit ⇒ Object
Returns the value of attribute unit.
-
#weight ⇒ Object
Returns the value of attribute weight.
Attributes inherited from Model::Base
#_id, #_slugs, #created_at, #parent, #updated_at
Instance Method Summary collapse
- #attributes ⇒ Object
-
#initialize(attributes = {}, parent = nil) ⇒ Variant
constructor
A new instance of Variant.
- #qty_available ⇒ Object
- #sold_out? ⇒ Boolean
Methods inherited from Model::Base
#==, #attributes=, #inspect, method_missing, #method_missing, #to_param, #url
Constructor Details
#initialize(attributes = {}, parent = nil) ⇒ Variant
Returns a new instance of Variant.
29 30 31 32 33 |
# File 'lib/cornerstore/api/variant.rb', line 29 def initialize(attributes = {}, parent = nil) self.price = Cornerstore::Price.new(attributes.delete('price')) self.properties = Cornerstore::Property::Resource.new(self, attributes.delete('properties') || []) super end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Cornerstore::Model::Base
Instance Attribute Details
#differentiating_properties ⇒ Object
Returns the value of attribute differentiating_properties.
2 3 4 |
# File 'lib/cornerstore/api/variant.rb', line 2 def differentiating_properties @differentiating_properties end |
#offer ⇒ Object Also known as: offer?
Returns the value of attribute offer.
2 3 4 |
# File 'lib/cornerstore/api/variant.rb', line 2 def offer @offer end |
#order_number ⇒ Object
Returns the value of attribute order_number.
2 3 4 |
# File 'lib/cornerstore/api/variant.rb', line 2 def order_number @order_number end |
#oversell ⇒ Object
Returns the value of attribute oversell.
2 3 4 |
# File 'lib/cornerstore/api/variant.rb', line 2 def oversell @oversell end |
#price ⇒ Object
Returns the value of attribute price.
2 3 4 |
# File 'lib/cornerstore/api/variant.rb', line 2 def price @price end |
#properties ⇒ Object
Returns the value of attribute properties.
2 3 4 |
# File 'lib/cornerstore/api/variant.rb', line 2 def properties @properties end |
#qty_in_stock ⇒ Object
Returns the value of attribute qty_in_stock.
2 3 4 |
# File 'lib/cornerstore/api/variant.rb', line 2 def qty_in_stock @qty_in_stock end |
#qty_reserved ⇒ Object
Returns the value of attribute qty_reserved.
2 3 4 |
# File 'lib/cornerstore/api/variant.rb', line 2 def qty_reserved @qty_reserved end |
#unit ⇒ Object
Returns the value of attribute unit.
2 3 4 |
# File 'lib/cornerstore/api/variant.rb', line 2 def unit @unit end |
#weight ⇒ Object
Returns the value of attribute weight.
2 3 4 |
# File 'lib/cornerstore/api/variant.rb', line 2 def weight @weight end |
Instance Method Details
#attributes ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/cornerstore/api/variant.rb', line 16 def attributes { order_number: order_number, price: price, qty_in_stock: qty_in_stock, qty_reserved: qty_reserved, offer: offer, oversell: oversell, weight: weight, unit: unit } end |
#qty_available ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/cornerstore/api/variant.rb', line 35 def qty_available if self.qty_in_stock and not self.oversell self.qty_in_stock - self.qty_reserved else Float::INFINITY end end |
#sold_out? ⇒ Boolean
43 44 45 |
# File 'lib/cornerstore/api/variant.rb', line 43 def sold_out? self.qty_available == 0 end |