#---
# 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'
class RulesBuilder13
  def load aStream
    result = eval(aStream.join("\n"))
    return result.subject
  end
end
class ConfigurationBuilder

  def self.item arg
    result = self.new
    result.item arg
    return result
  end
  def initialize
    @subject = Configuration.new
  end
  def item arg
    @current_item = Item.new(arg)
    @subject.add_item @current_item
    return self
  end

  attr_reader :subject
  def provides arg
    @current_item.add_provision arg.subject
    return self
  end
  def uses arg
    @current_item.add_usage arg.subject
    return self
  end
  def depends_on arg
    @current_item.add_dependency(@subject[arg])
    self
  end
end

class Resources
  class << self
    def electricity power
      return ElectricityBuilder.new(power)
    end

    def acid
      return AcidBuilder.new
    end
  end
end

class AcidBuilder
  attr_reader :subject
  def initialize
    @subject = Acid.new
  end
  def type arg
    subject.type = arg
    self
  end
  def grade arg
    subject.grade = arg
    self
  end
end

class ElectricityBuilder
  attr_reader :subject
  def initialize arg
    @subject = Electricity.new arg
  end
end

    
