Class: ShopPackage
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- ShopPackage
- Defined in:
- app/models/shop_package.rb
Class Method Summary collapse
-
.attrs ⇒ Object
Returns attributes attached to the product.
-
.inclde ⇒ Object
Returns the objects to include.
-
.methds ⇒ Object
Returns methods with usefuly information.
-
.params ⇒ Object
Returns a custom hash of attributes on the product.
Instance Method Summary collapse
-
#available_products ⇒ Object
Returns the products not attached to the category.
-
#category ⇒ Object
Not a valid option, but useful incase a tag is called.
-
#slug ⇒ Object
Returns the slug of the first product.
-
#to_json(*attrs) ⇒ Object
Overloads the base to_json to return what we want.
-
#url ⇒ Object
Returns the url of the first product.
-
#value ⇒ Object
Returns the aggregate value of the products in the package.
-
#weight ⇒ Object
Returns the aggregate weight of the products in the package.
Class Method Details
.attrs ⇒ Object
Returns attributes attached to the product
51 52 53 |
# File 'app/models/shop_package.rb', line 51 def attrs [ :id, :name, :price, :sku, :description, :created_at, :updated_at ] end |
.inclde ⇒ Object
Returns the objects to include
61 62 63 |
# File 'app/models/shop_package.rb', line 61 def inclde [ :category, :products ] end |
.methds ⇒ Object
Returns methods with usefuly information
56 57 58 |
# File 'app/models/shop_package.rb', line 56 def methds [] end |
.params ⇒ Object
Returns a custom hash of attributes on the product
66 67 68 |
# File 'app/models/shop_package.rb', line 66 def params { :only => self.attrs, :methods => self.methds, :include => self.inclde } end |
Instance Method Details
#available_products ⇒ Object
Returns the products not attached to the category
20 |
# File 'app/models/shop_package.rb', line 20 def available_products; ShopProduct.all - self.products; end |
#category ⇒ Object
Not a valid option, but useful incase a tag is called
29 |
# File 'app/models/shop_package.rb', line 29 def category; nil; end |
#slug ⇒ Object
Returns the slug of the first product
23 |
# File 'app/models/shop_package.rb', line 23 def slug; packings.first.product.slug; end |
#to_json(*attrs) ⇒ Object
Overloads the base to_json to return what we want
32 |
# File 'app/models/shop_package.rb', line 32 def to_json(*attrs); super self.class.params; end |
#url ⇒ Object
Returns the url of the first product
26 |
# File 'app/models/shop_package.rb', line 26 def url; packings.first.product.url; end |
#value ⇒ Object
Returns the aggregate value of the products in the package
35 36 37 38 39 |
# File 'app/models/shop_package.rb', line 35 def value value = 0 self.packings.map { |pkg| value += (pkg.product.price.to_f * pkg.quantity) } value end |
#weight ⇒ Object
Returns the aggregate weight of the products in the package
42 43 44 45 46 |
# File 'app/models/shop_package.rb', line 42 def weight weight = 0 self.packings.map { |pkg| weight += (pkg.product.weight.to_f * pkg.quantity) } weight end |