class BillHicks::Inventory

Inventory item response structure:

{
  product:  "...",
  upc:      "...",
  quantity: "..."
}

Constants

CHUNK_SIZE
INVENTORY_FILENAME

Public Class Methods

all(options = {}) click to toggle source
# File lib/bill_hicks/inventory.rb, line 29
def self.all(options = {})
  requires!(options, :username, :password)
  new(options).all
end
get_quantity_file(options = {}) click to toggle source
# File lib/bill_hicks/inventory.rb, line 19
def self.get_quantity_file(options = {})
  requires!(options, :username, :password)
  new(options).get_quantity_file
end
new(options = {}) click to toggle source
# File lib/bill_hicks/inventory.rb, line 14
def initialize(options = {})
  requires!(options, :username, :password)
  @options = options
end
quantity(options = {}) click to toggle source
# File lib/bill_hicks/inventory.rb, line 24
def self.quantity(options = {})
  requires!(options, :username, :password)
  new(options).all
end

Public Instance Methods

all() click to toggle source
# File lib/bill_hicks/inventory.rb, line 34
def all
  items             = []
  quantity_tempfile = get_file(INVENTORY_FILENAME)

  SmarterCSV.process(quantity_tempfile, {
    chunk_size: CHUNK_SIZE,
    force_utf8: true,
    convert_values_to_numeric: false,
    key_mapping: {
      product: :item_identifier,
      qty_avail: :quantity,
    }
  }) do |chunk|
    chunk.each do |item|
      items << item
    end
  end

  quantity_tempfile.close
  quantity_tempfile.unlink

  items
end
Also aliased as: quantity
get_quantity_file() click to toggle source
# File lib/bill_hicks/inventory.rb, line 58
def get_quantity_file
  quantity_tempfile = get_file(INVENTORY_FILENAME)
  tempfile          = Tempfile.new

  SmarterCSV.process(quantity_tempfile, {
    chunk_size: CHUNK_SIZE,
    force_utf8: true,
    convert_values_to_numeric: false,
    key_mapping: {
      product: :item_identifier,
      qty_avail: :quantity,
    }
  }) do |chunk|
    chunk.each do |item|
      tempfile.puts("#{item[:item_identifier]},#{item[:quantity]}")
    end
  end

  quantity_tempfile.close
  quantity_tempfile.unlink
  tempfile.close
  tempfile.path
end
quantity()
Alias for: all