Last active
August 29, 2015 14:22
-
-
Save jakenotjacob/6ed57267ab94d682ea73 to your computer and use it in GitHub Desktop.
Inventory and Cart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:GR1: | |
:name: Green Tea | |
:price: 3.11 | |
:SR1: | |
:name: Strawberries | |
:price: 5.00 | |
:CF1: | |
:name: Coffee | |
:price: 11.23 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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