title: Need help improving a Ruby DSL for controlling an Arduino controlled drink dispenser (bar monkey)
body: <p>I'm writing a DSL in Ruby to control an Arduino project I'm working on; Bardino.  It's a bar monkey that will be software controlled to serve drinks.  The Arduino takes commands via the serial port to tell the Arduino what pumps to turn on and for how long.</p>
  
  <p>It currently reads a recipe (see below) and prints it back out.  The code for serial communications still need to be worked in as well as some other ideas that I have mentioned below.</p>
  
  <p>This is my first DSL and I'm working off of a previous example so it's very rough around the edges.  Any critiques, code improvements (are there any good references for Ruby DSL best practices or idioms?) or any general comments.</p>
  
  <p>I currently have a rough draft of the DSL so a drink recipe looks like the following (<a href="http://github.com/mwilliams/barduino-tender/tree/571fb9128c02ce72b1f891d841930bf526f1432c/examples/water.rb" rel="nofollow noreferrer">Github link</a>):</p>
  
  <pre><code>desc "Simple glass of water"
  recipe "water" do
    ingredients(
    "Water" =&gt; 2.ounces
    )
  end
  </code></pre>
  
  <p>This in turn is interpreted and currently results with the following (<a href="http://github.com/mwilliams/barduino-tender/tree/571fb9128c02ce72b1f891d841930bf526f1432c/barduino-tender.rb" rel="nofollow noreferrer">Github link</a>):</p>
  
  <pre><code>[mwilliams@Danzig barduino-tender]$ ruby barduino-tender.rb examples/water.rb
  Preparing: Simple glass of water
  
  Ingredients:
   Water: 2 ounces
  </code></pre>
  
  <p>This is a good start for the DSL, however, I do think it could be implemented a little bit better.  Some ideas I had below:</p>
  
  <ol>
  <li>Defining what "ingredients" are available using the name of the ingredient and the number pump that it's connected to.  Maybe using a hash?  ingredients = {"water" => 1, "vodka" => 2}.  This way, when an ingredient is interpreted it can either a) send the pump number over the serial port followed by the number of ounces for the Arduino to dispense b) tell the user that ingredient does not exist and abort so nothing is dispensed c) easily have the capability to change or add new ingredients if they're changed.</li>
  <li>Making the recipe look less code like, which is the main purpose of a DSL, maybe build a recipe builder?  Using the available ingredients to prompt the user for a drink name, ingredients involved and how much?</li>
  </ol>
  
  <p>The Github project is <a href="http://github.com/mwilliams/barduino-tender/tree/master" rel="nofollow noreferrer">here</a>, feel free to fork and make pull requests, or post your code suggestions and examples here for other users to see.  And if you're at all curious, the Arduino code, using the Ruby Arduino Development framework is <a href="http://github.com/mwilliams/barduino/tree/master" rel="nofollow noreferrer">here</a>.</p>
  
  <p><strong>Update</strong></p>
  
  <p>I modified and cleaned things up a bit to reflect Orion Edwards suggestion for a recipe.  It now looks like the following.</p>
  
  <pre><code>description 'Screwdriver' do 
    serve_in 'Highball Glass'
    ingredients do
      2.ounces :vodka
      5.ounces :orange_juice
    end
  end
  </code></pre>
  
  <p>I also added a hash (key being the ingredient and the value the pump number it's hooked up to).  I think this provided much progress.  I'll leave the question open for any further suggestions for now, but will ultimately select Orion's answer.  The updated DSL code is <a href="http://github.com/mwilliams/barduino-tender/tree/master/barduino-tender.rb" rel="nofollow noreferrer">here</a>.</p>