Class: Zanders::Inventory

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

Constant Summary collapse

INVENTORY_FILENAME =
"liveinv.xml"

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

connect

Constructor Details

#initialize(options = {}) ⇒ Inventory

Returns a new instance of Inventory.



6
7
8
9
# File 'lib/zanders/inventory.rb', line 6

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

Class Method Details

.all(options = {}) ⇒ Object



11
12
13
14
# File 'lib/zanders/inventory.rb', line 11

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

.get_quantity_file(options = {}) ⇒ Object



16
17
18
19
# File 'lib/zanders/inventory.rb', line 16

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

.quantity(options = {}) ⇒ Object



21
22
23
24
# File 'lib/zanders/inventory.rb', line 21

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

Instance Method Details

#allObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/zanders/inventory.rb', line 26

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

  Nokogiri::XML(tempfile).xpath('//ZandersDataOut').each do |item|
    _map_hash = map_hash(item)

    items << _map_hash unless _map_hash.nil?
  end

  tempfile.close
  tempfile.unlink

  items
end

#get_quantity_fileObject



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/zanders/inventory.rb', line 42

def get_quantity_file
  inventory_tempfile = get_file(INVENTORY_FILENAME)
  tempfile           = Tempfile.new

  Nokogiri::XML(inventory_tempfile).xpath('//ZandersDataOut').each do |item|
    tempfile.puts("#{content_for(item, 'ITEMNO')},#{content_for(item, 'AVAILABLE')}")
  end

  inventory_tempfile.close
  inventory_tempfile.unlink
  tempfile.close
  tempfile.path
end