#---
# Excerpted from "The ThoughtWorks Anthology",
# published by The Pragmatic Bookshelf.
# Copyrights apply to this code. It may not be used to create training material, 
# courses, books, articles, and the like. Contact us if you are in doubt.
# We make no guarantees that this code is fit for any purpose. 
# Visit http://www.pragmaticprogrammer.com/titles/twa for more book information.
#---

require 'model'
require 'breakpoint'

class RulesBuilder10
  def load aStream
    builder = eval(aStream.join("\n"))
    return builder.configuration
  end
end

def load_configuration
  return RulesBuilder10.new  
end

class RulesBuilder10
  attr_reader :configuration

  def initialize
    @configuration = Configuration.new
    @capturing = nil
  end

  def item srcSymbol
    @current_item = Item.new srcSymbol
    @configuration.add_item @current_item
    self
  end

  def depends_on arg
    item = @configuration[arg]
    @current_item.add_dependency(item)
    self
  end

  def uses
    @capturing = :uses
    self
  end    

  def acid
    @current_resource = Acid.new
    capture @current_resource
    self
  end

  def capture arg
    case @capturing
    when :uses
      @current_item.add_usage arg
    when :provisions
      @current_item.add_provision arg
    end
  end    

  def type acidType
    @current_resource.type = acidType
    self
  end
  def grade aNumber
    @current_resource.grade = aNumber
    self
  end

  def electricity powerNumber
    @current_resource = Electricity.new(powerNumber)
    capture @current_resource
    self
  end
  
  def provides 
    @capturing = :provisions
    self
  end

end
