Class: Cornerstore::Product
- Inherits:
-
Model::Base
- Object
- Model::Base
- Cornerstore::Product
- Defined in:
- lib/cornerstore/api/product.rb
Defined Under Namespace
Classes: Resource
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#enabled ⇒ Object
Returns the value of attribute enabled.
-
#images ⇒ Object
Returns the value of attribute images.
-
#manufacturer ⇒ Object
Returns the value of attribute manufacturer.
-
#name ⇒ Object
Returns the value of attribute name.
-
#properties ⇒ Object
Returns the value of attribute properties.
-
#variants ⇒ Object
Returns the value of attribute variants.
Attributes inherited from Model::Base
#_id, #_slugs, #created_at, #parent, #updated_at
Instance Method Summary collapse
- #attributes ⇒ Object
- #cover_image ⇒ Object
-
#initialize(attributes = {}, parent = nil) ⇒ Product
constructor
A new instance of Product.
- #new? ⇒ Boolean
- #offer? ⇒ Boolean
- #order_number ⇒ Object
- #price ⇒ Object
- #sold_out? ⇒ Boolean
Methods inherited from Model::Base
#==, #attributes=, #inspect, method_missing, #method_missing, #to_param, #url
Constructor Details
#initialize(attributes = {}, parent = nil) ⇒ Product
Returns a new instance of Product.
10 11 12 13 14 15 |
# File 'lib/cornerstore/api/product.rb', line 10 def initialize(attributes = {}, parent = nil) self.images = Cornerstore::Image::Resource.new(self, attributes.delete('images') || [], 'images') self.variants = Cornerstore::Variant::Resource.new(self, attributes.delete('variants') || [], 'variants') self.properties = Cornerstore::Property::Resource.new(self, attributes.delete('properties') || [], '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
#description ⇒ Object
Returns the value of attribute description.
2 3 4 |
# File 'lib/cornerstore/api/product.rb', line 2 def description @description end |
#enabled ⇒ Object
Returns the value of attribute enabled.
2 3 4 |
# File 'lib/cornerstore/api/product.rb', line 2 def enabled @enabled end |
#images ⇒ Object
Returns the value of attribute images.
2 3 4 |
# File 'lib/cornerstore/api/product.rb', line 2 def images @images end |
#manufacturer ⇒ Object
Returns the value of attribute manufacturer.
2 3 4 |
# File 'lib/cornerstore/api/product.rb', line 2 def manufacturer @manufacturer end |
#name ⇒ Object
Returns the value of attribute name.
2 3 4 |
# File 'lib/cornerstore/api/product.rb', line 2 def name @name end |
#properties ⇒ Object
Returns the value of attribute properties.
2 3 4 |
# File 'lib/cornerstore/api/product.rb', line 2 def properties @properties end |
#variants ⇒ Object
Returns the value of attribute variants.
2 3 4 |
# File 'lib/cornerstore/api/product.rb', line 2 def variants @variants end |
Instance Method Details
#attributes ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/cornerstore/api/product.rb', line 17 def attributes { name: name, description: description, manufacturer: manufacturer, enabled: enabled } end |
#cover_image ⇒ Object
46 47 48 |
# File 'lib/cornerstore/api/product.rb', line 46 def cover_image @cover_image ||= self.images.to_a.find {|i| i.cover == true } end |
#new? ⇒ Boolean
42 43 44 |
# File 'lib/cornerstore/api/product.rb', line 42 def new? self.created_at >= 2.weeks.ago end |
#offer? ⇒ Boolean
38 39 40 |
# File 'lib/cornerstore/api/product.rb', line 38 def offer? variants.any? { |v| v.offer? } end |
#order_number ⇒ Object
30 31 32 |
# File 'lib/cornerstore/api/product.rb', line 30 def order_number variants.many? ? :many : variants.first.order_number end |
#price ⇒ Object
26 27 28 |
# File 'lib/cornerstore/api/product.rb', line 26 def price variants.collect { |v| v.price }.sort.first end |
#sold_out? ⇒ Boolean
34 35 36 |
# File 'lib/cornerstore/api/product.rb', line 34 def sold_out? variants.all? { |v| v.sold_out? } end |