Class: Zanders::Catalog
Constant Summary collapse
- CATALOG_FILENAME =
"zandersinv.xml"
Class Method Summary collapse
Instance Method Summary collapse
- #all(chunk_size, &block) ⇒ Object
-
#initialize(options = {}) ⇒ Catalog
constructor
A new instance of Catalog.
Methods inherited from Base
Constructor Details
#initialize(options = {}) ⇒ Catalog
Returns a new instance of Catalog.
6 7 8 9 10 11 12 13 |
# File 'lib/zanders/catalog.rb', line 6 def initialize( = {}) requires!(, :username, :password) = if [:full_product].present? self.load_descriptions end end |
Class Method Details
.all(chunk_size = 15, options = {}, &block) ⇒ Object
15 16 17 18 |
# File 'lib/zanders/catalog.rb', line 15 def self.all(chunk_size = 15, = {}, &block) requires!(, :username, :password) new().all(chunk_size, &block) end |
Instance Method Details
#all(chunk_size, &block) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/zanders/catalog.rb', line 20 def all(chunk_size, &block) chunker = Zanders::Chunker.new(chunk_size) tempfile = get_file(CATALOG_FILENAME) xml_doc = Nokogiri::XML(tempfile.open) xml_doc.xpath("//ZandersDataOut").each do |item| if chunker.is_full? yield(chunker.chunk) chunker.reset! else chunker.add(map_hash(item, [:full_product].present?)) end end if chunker.chunk.count > 0 yield(chunker.chunk) end tempfile.unlink end |