#---
# 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'

# problem here due to elec. If elec is immutable value, is tricky
# to set in resource holder.

class RulesBuilder9
  def load aStream
    $config = Configuration.new
    eval(aStream.join("\n"))
    return $config
  end
end

def item name
  $current_item = Item.new(name)
  $config.add_item $current_item
end

def uses resource
  $current_item.add_usage(resource)
end

def acid_type type
  $current_acid.type = type
end

def acid_grade grade
  $current_acid.grade = grade
end

def provides resource
  $current_item.add_provision(resource)
end

def depends supplier
  $current_item.add_dependency($config[supplier])
end


def acid
  $current_acid = Acid.new
end

def electricity
  $current_electricity = Electricity.new(0)
end

def electricity_power arg
  $current_electricity.power = arg
end

#this breaks the set once model - but tricky to get around this
# would need a more complex impl here
class Electricity
    def power= arg
        @power = arg
    end
end 

