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 = {}, &block) ⇒ Object



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

def self.all(options = {}, &block)
  requires!(options, :username, :password)
  new(options).all &block
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 = {}, &block) ⇒ Object



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

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

Instance Method Details

#all(&block) ⇒ Object



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

def all(&block)
  tempfile = get_file(INVENTORY_FILENAME)

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

  tempfile.close
  tempfile.unlink
end

#get_quantity_fileObject



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/zanders/inventory.rb', line 37

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