Class: ShopLineItem

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/shop_line_item.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.attrsObject

Returns attributes attached to the product



30
31
32
# File 'app/models/shop_line_item.rb', line 30

def attrs
  [ :id, :quantity ]
end

.methdsObject

Returns methods with usefuly information



35
36
37
# File 'app/models/shop_line_item.rb', line 35

def methds
  [ :price, :weight ]
end

.paramsObject

Returns a custom hash of attributes on the product



40
41
42
# File 'app/models/shop_line_item.rb', line 40

def params
  { :only  => attrs, :methods => methds }
end

Instance Method Details

#priceObject



15
16
17
# File 'app/models/shop_line_item.rb', line 15

def price
  (item_price.to_f * self.quantity).to_f
end

#to_json(*attrs) ⇒ Object

Overloads the base to_json to return what we want



25
# File 'app/models/shop_line_item.rb', line 25

def to_json(*attrs); super self.class.params; end

#weightObject



19
20
21
22
# File 'app/models/shop_line_item.rb', line 19

def weight
  warn 'Not yet fully implemented'
  (item.weight.to_f * self.quantity.to_f).to_f
end