I am writing DSL in Ruby to manage the Arduino project I am working on; Bardino. This is a monkey bar, which will be controlled by software for serving drinks. The Arduino receives commands through the serial port to tell the Arduino which pumps to turn on and for how long.
He is currently reading the recipe (see below) and printing it back. The code for serial communication has yet to be processed, as well as some other ideas that I talked about below.
This is my first DSL, and I am working on the previous example, so it is very rough around the edges. Any criticisms, code improvements (are there any good links to Ruby DSL best practices or idioms?), Or any general comments.
I currently have a draft DSL, so the drink recipe is as follows ( Github link ):
desc "Simple glass of water" recipe "water" do ingredients( "Water" => 2.ounces ) end
This, in turn, is interpreted and currently leads to the following ( Github link ):
[ mwilliams@Danzig barduino-tender]$ ruby barduino-tender.rb examples/water.rb Preparing: Simple glass of water Ingredients: Water: 2 ounces
This is a good start for DSL, but I think it can be implemented a little better. Some ideas that I had below:
- Identify available “ingredients” using the name of the ingredient and the number of pumps to which it is connected. Maybe use a hash? ingredients = {"water" => 1, "vodka" => 2}. Thus, when an ingredient is interpreted, it can either: a) send the pump number on the serial port, followed by the number of ounces for the Arduino, to discard it; b) inform the user that this ingredient does not exist and is interrupted, so nothing is released; c) they may easily be able to modify or add new ingredients if modified.
- How to make a recipe less like code, which is the main goal of DSL, maybe build a recipe builder? Using available ingredients to offer the user the name of the drink, the ingredients and how much?
The Github project is here , feel free to fork and make pull requests, or post your suggestions and code examples here to other users. see. And if you're curious at all, Arduino code using the Ruby Arduino Development framework is here .
Update
I changed and cleaned things up a bit to reflect Orion Edwards' offer for the recipe. Now it looks as follows.
description 'Screwdriver' do serve_in 'Highball Glass' ingredients do 2.ounces :vodka 5.ounces :orange_juice end end
I also added a hash (the key, which is the ingredient and the value of the number of the pump to which it connected). I think this has made significant progress. I will leave the question open for any further suggestions, but in the end we will choose Orion's answer. Updated DSL code here .
ruby language-design dsl arduino
mwilliams
source share