#---
# 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 RulesBuilder12
  def load aStream
    result = eval(aStream.join("\n"))
    return Configuration.current
  end
end
class Configuration
  def self.load 
    @@current = Configuration.new
  end
  load

  def self.item arg
    new_item = ItemBuilder.new(arg)
    @@current.add_item new_item.subject
    return new_item
  end

  def self.current
    @@current
  end    
end

class ItemBuilder

  attr_reader :subject
  def initialize arg
    @subject = Item.new arg
  end
  def provides arg
    subject.add_provision arg.subject
    return self
  end

  def uses arg
    subject.add_usage arg.subject
    return self
  end
  def depends_on arg
    subject.add_dependency(Configuration.current[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 set_type arg
    subject.type = arg
    self
  end
  def set_grade arg
    subject.grade = arg
    self
  end
end

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

    
