Class: Fdcart
- Inherits:
-
Object
- Object
- Fdcart
- Defined in:
- lib/fdcart.rb,
lib/fdcart/version.rb
Constant Summary collapse
- VERSION =
'0.2.2'
Instance Method Summary collapse
- #add(part, count, *extra) ⇒ Object
- #get ⇒ Object
- #get_by_belongs_ids(ids: []) ⇒ Object
- #get_by_ids(ids: []) ⇒ Object
-
#initialize(owner) ⇒ Fdcart
constructor
A new instance of Fdcart.
- #remove(id) ⇒ Object
Constructor Details
#initialize(owner) ⇒ Fdcart
Returns a new instance of Fdcart.
3 4 5 |
# File 'lib/fdcart.rb', line 3 def initialize(owner) @owner = owner end |
Instance Method Details
#add(part, count, *extra) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/fdcart.rb', line 6 def add(part, count, *extra) cart = nil count.to_i.times do cart = { part: part, owner: @owner } extra.each do |val| if val if !val[:externo].blank? cart[:proveedor_externo] = val[:externo] elsif val.is_a?(Almacen) cart[:part_owner] = val elsif val.is_a?(PluginVentaPrecio) cart[:transporte] = val elsif val.is_a?(OrdenReparacion) cart[:belongs] = val elsif val.is_a?(User) cart[:user] = val end end end cart = Cart.create!(cart) end cart || nil end |
#get ⇒ Object
37 38 39 |
# File 'lib/fdcart.rb', line 37 def get Cart.where(owner: @owner) end |
#get_by_belongs_ids(ids: []) ⇒ Object
44 45 46 47 48 |
# File 'lib/fdcart.rb', line 44 def get_by_belongs_ids(ids: []) Cart.where( :belongs_id.in => ids ) end |
#get_by_ids(ids: []) ⇒ Object
41 42 43 |
# File 'lib/fdcart.rb', line 41 def get_by_ids(ids: []) get.where(:_id.in => ids) end |
#remove(id) ⇒ Object
33 34 35 |
# File 'lib/fdcart.rb', line 33 def remove(id) Cart.find(id)&.destroy end |