Skip to content

Commit

Permalink
Output logging pattern created
Browse files Browse the repository at this point in the history
  • Loading branch information
skylerto committed Jul 2, 2015
1 parent 949f890 commit cea0621
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 47 deletions.
4 changes: 3 additions & 1 deletion input/commands/showcommand.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require_relative 'command'
require_relative '../inputbuffer'
require_relative '../../system/inventory'
require_relative '../../output/outputbuffer'


class ShowCommand < Command

Expand All @@ -9,7 +11,7 @@ def initialize()
end

def execute()
puts Inventory.instance.print
OutputBuffer.instance.insert(Inventory.instance.print)
end

def unexecute()
Expand Down
17 changes: 11 additions & 6 deletions input/inputhandler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
require_relative 'bufferinvoker'
require_relative '../system/inventory'
require_relative '../system/bag'
require_relative '../output/outputbuffer'

module Parser

def Parser.pp
Expand All @@ -14,10 +16,10 @@ def Parser.pp
# Begin the parseing of input
def Parser.parse
commands = ["add {item} {amount}", "order {item} {amount} ... ", "show", "check {item} {amount}"]
puts "Structure: {command} {arguments*}"
puts commands
OutputBuffer.instance.insert("Structure: {command} {arguments*}")
OutputBuffer.instance.insert(commands)
@invoker = BufferInvoker.new()

puts OutputBuffer.instance.string
begin
print "% "
#Parser::pp
Expand Down Expand Up @@ -58,10 +60,13 @@ def Parser.parse
else
puts "Command not valid"
end
Inventory.instance.print unless command.eql?("show")

OutputBuffer.instance.insert(Inventory.instance.print) unless command == "show"
puts OutputBuffer.instance.string
end until command == "exit"
puts "Finishing up.."
puts "Done"
OutputBuffer.instance.insert("Finishing up..")
OutputBuffer.instance.insert("Done")
puts OutputBuffer.instance.string
end
end

Expand Down
8 changes: 5 additions & 3 deletions output/outputbuffer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ def initialize()
@buffer = []
end

def insert(n, token)
@buffer.insert( n, token )
def insert(token)
@buffer << token
end

def string()
return @buffer.join( " " )
buff = @buffer.join( "\n" )
@buffer = []
return buff
end

def remove(n)
Expand Down
35 changes: 0 additions & 35 deletions output/outputformatter.rb

This file was deleted.

Empty file removed output/outputhandler.rb
Empty file.
Binary file removed system/.bag.rb.swp
Binary file not shown.
12 changes: 10 additions & 2 deletions system/bag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,15 @@ def each(&block)
## => Formating
# Let me know how many things are in my bag man.
def print
puts "Current Inventory"
@bag.each {|item, amount| puts " #{item}: #{amount}"}
buffer = []
if @bag.empty?
buffer << "Bag is empty"
else
buffer << "Current Inventory"
@bag.each do |item, amount|
buffer << " #{item}: #{amount}"
end
end
buffer
end
end

0 comments on commit cea0621

Please sign in to comment.