class MgeWholesale::Inventory

Constants

FULL_INVENTORY_FILENAME
INVENTORY_FILENAME

Public Class Methods

all(options = {}) click to toggle source
# File lib/mge_wholesale/inventory.rb, line 12
def self.all(options = {})
  requires!(options, :username, :password)
  new(options).all
end
new(options = {}) click to toggle source
# File lib/mge_wholesale/inventory.rb, line 7
def initialize(options = {})
  requires!(options, :username, :password)
  @options = options
end
quantity(options = {}) click to toggle source
# File lib/mge_wholesale/inventory.rb, line 17
def self.quantity(options = {})
  requires!(options, :username, :password)
  new(options).quantity
end

Public Instance Methods

all() click to toggle source
# File lib/mge_wholesale/inventory.rb, line 22
def all
  items    = []
  tempfile = get_file(INVENTORY_FILENAME)

  CSV.foreach(tempfile, { headers: :first_row }).each do |row|
    item = {
      item_identifier: row['id'],
      quantity:        row['qty'].to_i,
      price:           row['cost'],
    }

    items << item
  end

  tempfile.unlink

  items
end
quantity() click to toggle source
# File lib/mge_wholesale/inventory.rb, line 41
def quantity
  items    = []
  tempfile = get_file(FULL_INVENTORY_FILENAME)

  CSV.foreach(tempfile, { headers: :first_row }).each do |row|
    item = {
      item_identifier: row['id'],
      quantity:        row['qty'].to_i,
    }

    items << item
  end

  tempfile.unlink

  items
end