From 64da0a3c03cec708a88591d218194d64538dfccb Mon Sep 17 00:00:00 2001 From: Nathan Lasseter Date: Sun, 16 Jun 2013 14:57:54 +0100 Subject: Initial Commit --- README.textile | 5 +++++ tapelibrary.rb | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ ystv.rb | 30 ++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 README.textile create mode 100644 tapelibrary.rb create mode 100644 ystv.rb diff --git a/README.textile b/README.textile new file mode 100644 index 0000000..7d6f566 --- /dev/null +++ b/README.textile @@ -0,0 +1,5 @@ +h1. TapeLibrary + +h2. A Ruby Tape Library DSL + +Wanted to play with Docile. Had nothing better to do. 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 diff --git a/ystv.rb b/ystv.rb new file mode 100644 index 0000000..2d90802 --- /dev/null +++ b/ystv.rb @@ -0,0 +1,30 @@ +ystvlib = library "ystv" do + tape "ystv01" + tape "ystv02" + tape "ystv03" + tape "ystv04" + tape "ystv05" + tape "ystv06" + tape "ystv07" + tape "ystv08" + tape "ystv09" + tape "ystv10" +end + +urylib = library "ury" do + tape "ury001", :slot => 11 + tape "ury002", :slot => 12 + tape "ury003", :slot => 13 + tape "ury004", :slot => 14 + tape "ury005", :slot => 15 + tape "ury006", :slot => 16 + tape "ury007", :slot => 17 + tape "ury008", :slot => 18 + tape "ury009", :slot => 19 + tape "ury010", :slot => 20 +end + +tapebackup = robot "tapebackup" do + uselibrary "ystv", ystvlib + uselibrary "ury", urylib +end -- cgit v1.2.1