Class: MgeWholesale::Inventory

Inherits:
Base
  • Object
show all
Defined in:
lib/mge_wholesale/inventory.rb

Constant Summary collapse

INVENTORY_FILENAME =
'exportXML_cq_barcodeFFL.csv'.freeze
FULL_INVENTORY_FILENAME =
'exportXML_cq_barcodeFFL_all.csv'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

connect

Constructor Details

#initialize(options = {}) ⇒ Inventory

Returns a new instance of Inventory.



7
8
9
10
# File 'lib/mge_wholesale/inventory.rb', line 7

def initialize(options = {})
  requires!(options, :username, :password)
  @options = options
end

Class Method Details

.all(options = {}) ⇒ Object



12
13
14
15
# File 'lib/mge_wholesale/inventory.rb', line 12

def self.all(options = {})
  requires!(options, :username, :password)
  new(options).all
end

.quantity(options = {}) ⇒ Object



17
18
19
20
# File 'lib/mge_wholesale/inventory.rb', line 17

def self.quantity(options = {})
  requires!(options, :username, :password)
  new(options).quantity
end

Instance Method Details

#allObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/mge_wholesale/inventory.rb', line 22

def all
  items    = []
  tempfile = get_file(INVENTORY_FILENAME)

  CSV.foreach(tempfile, { headers: :first_row }).each do |row|
    item = {
      item_identifier: row['id'],
      quantity:        row['qty'].to_i,
      price:           row['cost'],
    }

    items << item
  end

  tempfile.unlink

  items
end

#quantityObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/mge_wholesale/inventory.rb', line 41

def quantity
  items    = []
  tempfile = get_file(FULL_INVENTORY_FILENAME)

  CSV.foreach(tempfile, { headers: :first_row }).each do |row|
    item = {
      item_identifier: row['id'],
      quantity:        row['qty'].to_i,
    }

    items << item
  end

  tempfile.unlink

  items
end