Class: Fdcart

Inherits:
Object
  • Object
show all
Defined in:
lib/fdcart.rb,
lib/fdcart/version.rb

Constant Summary collapse

VERSION =
'0.2.2'

Instance Method Summary collapse

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

#getObject



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