Class: Zanders::Inventory

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

Constant Summary collapse

INVENTORY_FILENAME =
"zandersinv.csv"
QUANTITY_FILENAME =
"liveinv.csv"

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

connect, requires!

Constructor Details

#initialize(options = {}) ⇒ Inventory

Returns a new instance of Inventory.



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

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

  @options = options
end

Class Method Details

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



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

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

.quantities(chunk_size = 15, options = {}, &block) ⇒ Object



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

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

Instance Method Details

#all(chunk_size, &block) ⇒ Object



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

def all(chunk_size, &block)
  connect(@options) do |ftp|
    csv_tempfile = Tempfile.new

    ftp.chdir(Zanders.config.ftp_directory)
    ftp.getbinaryfile(INVENTORY_FILENAME, csv_tempfile.path)

    SmarterCSV.process(csv_tempfile, { :chunk_size => chunk_size, :convert_values_to_numeric => false }) do |chunk|
      yield(chunk)
    end

    csv_tempfile.unlink
  end
end

#quantities(chunk_size, &block) ⇒ Object



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

def quantities(chunk_size, &block)
  connect(@options) do |ftp|
    csv_tempfile = Tempfile.new

    ftp.chdir(Zanders.config.ftp_directory)
    ftp.getbinaryfile(QUANTITY_FILENAME, csv_tempfile.path)

    SmarterCSV.process(csv_tempfile, { :chunk_size => chunk_size, :convert_values_to_numeric => false }) do |chunk|
      yield(chunk)
    end

    csv_tempfile.unlink
  end
end