Class: OrionWholesale::Inventory

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

connect

Constructor Details

#initialize(options = {}) ⇒ Inventory

Returns a new instance of Inventory.



4
5
6
7
# File 'lib/orion_wholesale/inventory.rb', line 4

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

Class Method Details

.all(options = {}) ⇒ Object



9
10
11
12
# File 'lib/orion_wholesale/inventory.rb', line 9

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

.quantity(options = {}) ⇒ Object



14
15
16
17
# File 'lib/orion_wholesale/inventory.rb', line 14

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

Instance Method Details

#allObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/orion_wholesale/inventory.rb', line 19

def all
  tempfile = get_most_recent_file(OrionWholesale.config.catalog_filename_prefix, OrionWholesale.config.top_level_dir)
  items = []

  File.open(tempfile).each_with_index do |row, i|
    row = row.split("\t")
    
    if i==0
      @headers = row
      next
    end

    item = {
      item_identifier: row[@headers.index('Item ID')].strip,
      quantity:        row[@headers.index('Qty available')].to_i,
      price:           row[@headers.index('Price')].strip,
    }

    items << item
  end

  tempfile.close
  tempfile.unlink

  items
end

#quantityObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/orion_wholesale/inventory.rb', line 46

def quantity
  tempfile = get_most_recent_file(OrionWholesale.config.catalog_filename_prefix, OrionWholesale.config.top_level_dir)
  items = []

  File.open(tempfile).each_with_index do |row, i|
    row = row.split("\t")
    
    if i==0
      @headers = row
      next
    end

    item = {
      item_identifier: row[@headers.index('Item ID')].strip,
      quantity:        row[@headers.index('Qty available')].to_i,
    }

    items << item
  end

  tempfile.close
  tempfile.unlink

  items
end