diff options
author | Nathan Lasseter <nathan@4574.co.uk> | 2013-06-16 14:57:54 +0100 |
---|---|---|
committer | Nathan Lasseter <nathan@4574.co.uk> | 2013-06-16 14:57:54 +0100 |
commit | 64da0a3c03cec708a88591d218194d64538dfccb (patch) | |
tree | b1d85b734391072a8e43b6e8aace9ddea0b4bbff /tapelibrary.rb |
Initial Commit
Diffstat (limited to 'tapelibrary.rb')
-rw-r--r-- | tapelibrary.rb | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/tapelibrary.rb b/tapelibrary.rb new file mode 100644 index 0000000..daf0e2e --- /dev/null +++ b/tapelibrary.rb @@ -0,0 +1,48 @@ +require 'rubygems' +require 'docile' + +Library = Struct.new(:name, :tapes) + +class LibraryBuilder + def initialize name + @name = name + @nextslot = 1 + @tapes = Hash.new + end + def tape name, opts = {} + slot = opts[:slot] + if slot.nil? then + @tapes[name] = @nextslot + @nextslot += 1 + else + @nextslot += 1 if slot == @nextslot + @tapes[name] = slot + end + end + def build + Library.new @name, @tapes + end +end + +def library name, &block + Docile.dsl_eval(LibraryBuilder.new(name), &block).build +end + +Robot = Struct.new(:name, :libraries) + +class RobotBuilder + def initialize name + @name = name + @libraries = Hash.new + end + def uselibrary name, library + @libraries[name] = library + end + def build + Robot.new @name, @libraries + end +end + +def robot name, &block + Docile.dsl_eval(RobotBuilder.new(name), &block).build +end |