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
10
# File 'lib/zanders/inventory.rb', line 6

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

  @options = options
end

Class Method Details

.all(chunk_size = 100, options = {}, &block) ⇒ Object



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

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

.get_file(options = {}) ⇒ Object



27
28
29
30
# File 'lib/zanders/inventory.rb', line 27

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

.get_quantity_file(options = {}) ⇒ Object



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

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

.quantity(chunk_size = 100, options = {}, &block) ⇒ Object



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

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

Instance Method Details

#all(chunk_size, &block) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/zanders/inventory.rb', line 32

def all(chunk_size, &block)
  tempfile  = get_file(INVENTORY_FILENAME)
  xml_doc   = Nokogiri::XML(tempfile.open)

  xml_doc.xpath('//ZandersDataOut').each do |item|
    map_hash(item)
  end

  tempfile.unlink
end

#get_quantity_fileObject



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

def get_quantity_file
  inventory_tempfile  = get_file(INVENTORY_FILENAME)
  tempfile            = Tempfile.new
  xml_doc             = Nokogiri::XML(inventory_tempfile.open)

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

  inventory_tempfile.unlink
  tempfile.close

  tempfile.path
end