class SportsmansSupply::Inventory

Public Class Methods

all(options = {}) click to toggle source
# File lib/sportsmans-supply/inventory.rb, line 9
def self.all(options = {})
  requires!(options, :username, :password)
  new(options).all
end
Also aliased as: quantity
new(options = {}) click to toggle source
# File lib/sportsmans-supply/inventory.rb, line 4
def initialize(options = {})
  requires!(options, :username, :password)
  @options = options
end
quantity(options = {})
Alias for: all

Public Instance Methods

all() click to toggle source
# File lib/sportsmans-supply/inventory.rb, line 15
def all
  inventory_file = get_file(SportsmansSupply.config.inventory_filename, 'pricing-availability')
  inventory_data = []

  File.open(inventory_file).each_with_index do |row, i|
    row = row.split(",").map(&:strip)

    if i == 0
      @headers = row.map(&:downcase)
      next
    end

    inventory_data << {
      item_identifier: row[@headers.index('sku')],
      quantity:        row[@headers.index('qty')].to_i,
      price:           row[@headers.index('rapid retail price')].to_f,
    }
  end

  inventory_file.close
  inventory_file.unlink

  inventory_data
end