Skip to content

Instantly share code, notes, and snippets.

@jakenotjacob
Last active August 29, 2015 14:22
Show Gist options
  • Save jakenotjacob/6ed57267ab94d682ea73 to your computer and use it in GitHub Desktop.
Save jakenotjacob/6ed57267ab94d682ea73 to your computer and use it in GitHub Desktop.
Inventory and Cart
:GR1:
:name: Green Tea
:price: 3.11
:SR1:
:name: Strawberries
:price: 5.00
:CF1:
:name: Coffee
:price: 11.23
class Checkout
def initialize
@basket = {}
end
def scan(item)
product_code = item.keys.first
if @basket.has_key? product_code
@basket[:product_code][:quantity] += 1
else
@basket[:product_code] = item
@basket[:product_code][:quantity] = 0
end
end
end
require 'yaml'
INVENTORY_LIST = File.join(File.dirname(__FILE__), "..", "config/", "inventory.yaml")
class Inventory
attr_reader :items
def initialize
@items = YAML.load_file INVENTORY_LIST
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment