#---
# 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 RulesBuilder17
  def load aStream
    eval(aStream.join("\n"))
    rules =  PrimaryConfigurationRules.new
    rules.run
    return rules.subject
  end
end

class ConfigurationBuilder
  def initialize
    @subject = Configuration.new
  end
  def item arg
    result = ItemBuilder.new self, arg
    @subject.add_item result.subject
    return result
  end
  attr_reader :subject
  def acid
    return AcidBuilder.new
  end
  def electricity power
    return ElectricityBuilder.new(power)
  end
end

class ItemBuilder
  attr_reader :subject, :parent
  def item arg
    @parent.item arg
  end
  def initialize parent, arg
    @parent = parent
    @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[arg])
    return self
  end
  def configuration
    return @parent.subject
  end
end

class Resources
  class << self

  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


