Class: Zanders::Catalog

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

Constant Summary collapse

CATALOG_FILENAME =
'zandersinv.xml'.freeze
ITEM_NODE_NAME =
'ZandersDataOut'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

connect

Constructor Details

#initialize(options = {}) ⇒ Catalog

Returns a new instance of Catalog.



7
8
9
10
# File 'lib/zanders/catalog.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/zanders/catalog.rb', line 12

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

Instance Method Details

#allObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/zanders/catalog.rb', line 17

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

  Nokogiri::XML::Reader.from_io(tempfile, nil, Zanders.config.file_encoding).each do |reader|
    next unless reader.node_type == Nokogiri::XML::Reader::TYPE_ELEMENT
    next unless reader.name == ITEM_NODE_NAME

    node = Nokogiri::XML.parse(reader.outer_xml)

    _map_hash = map_hash(node.css(ITEM_NODE_NAME))

    items << _map_hash unless _map_hash.nil?
  end

  tempfile.close
  tempfile.unlink

  items
end