Last active
August 29, 2015 14:13
-
-
Save KaraAJC/45795d36675232589b79 to your computer and use it in GitHub Desktop.
trying to get challenge 1
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 InventoryItem | |
attr_accessor :name, :inventory | |
def initialize(args) | |
@name = args[:name] | |
@inventory = args[:inventory] | |
end | |
def count_items(item) | |
#self.inventory.each do |key, value| | |
item.each do |key, value| | |
puts "key is #{key}, and value is #{value}" | |
# value.each do |color, amount| | |
# puts "we've got #{amount} #{color} items" | |
# end | |
end | |
#return total amount | |
end | |
def first_column_items | |
#return items that appear in left column of 3 column layout | |
end | |
end | |
stuff = [{:name => "shoe", :inventory => {"brown" => 5, "blue" => 4, "white" => 3, "gray" => 2, "black" => 1}}, | |
{:name => "shirt", :inventory => {"brown" => 3, "blue" => 2, "white" => 1, "gray" => 4, "black" => 3}}, | |
{:name => "glove", :inventory => {"brown" => 1, "blue" => 9, "white" => 56, "gray" => 67, "black" => 9}}, | |
{:name => "sock", :inventory => {"brown" => 58, "blue" => 6, "white" => 1, "gray" => 26, "black" => 2}}, | |
{:name => "hat", :inventory => {"brown" => 3, "blue" => 8, "white" => 6, "gray" => 3, "black" => 8}} | |
] | |
inventory = stuff.each { |item| InventoryItem.new(item) } | |
p inventory[1][:inventory] | |
shoes = inventory[0] | |
shoes.count_items |
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_relative 'items.rb' | |
describe InventoryItem do | |
before :each do | |
# Create an array of 5 items here and name it @items | |
@items = [ InventoryItem.new({:name => "shoe", :inventory => {"brown" => 5, "blue" => 4, "white" => 3, "gray" => 2, "black" => 1}}), | |
InventoryItem.new({:name => "shirt", :inventory => {"brown" => 7, "blue" => 5, "white" => 6, "gray" => 8, "black" => 2}}), | |
InventoryItem.new({:name => "glove", :inventory => {"brown" => 3, "blue" => 6, "white" => 5, "gray" => 3, "black" => 7}}), | |
InventoryItem.new({:name => "hat", :inventory => {"brown" => 4, "blue" => 6, "white" => 8, "gray" => 9, "black" => 2}}), | |
InventoryItem.new({:name => "sock", :inventory => {"brown" => 6, "blue" => 4, "white" => 9, "gray" => 2, "black" => 3}})] | |
# - the InventoryItems should have the names of 'shoe', 'shirt', 'glove', 'hat', and 'sock', in that order | |
# - each item should have an inventory that records the number of items of that color that are in stock | |
# - the first item (the shoe) has five `'brown'`, four `'blue'`, three `'white'`, two `'gray'`, and one `'black'` in stock. | |
end | |
# Do NOT modify any of these tests. | |
describe '#items' do | |
it 'includes a collection of shoes in an array' do | |
expect(@items).to be_kind_of Array | |
end | |
it 'has a collection of InventoryItem objects' do | |
expect(@items.first).to be_a InventoryItem | |
expect(@items).to all be_a(InventoryItem) | |
end | |
it 'includes five InventoryItem objects' do | |
expect(@items.length).to eq 5 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment