‘rufus-decision’ csv decision tables
This is the latest episode of my move to Rufus of some of the OpenWFEru subprojects.
The ‘rufus-decision‘ gem contains a Ruby implementation of [CSV] decision tables.
After
sudo gem install -y rufus-decision
given that table :

you can have :
require 'rubygems'
require 'rufus/decision'
include Rufus
TABLE = DecisionTable.new("""
in:age,in:trait,out:salesperson
18..35,,adeslky
25..35,,bronco
36..50,,espadas
51..78,,thorsten
44..120,,ojiisan
25..35,rich,kerfelden
,cheerful,swanson
,maniac,korolev
""")
#
# Given a customer (a Hash instance directly, for
# convenience), returns the name of the first
# corresponding salesman.
#
def determine_salesperson (customer)
TABLE.transform(customer)["salesperson"]
end
puts determine_salesperson(
"age" => 72)
# => thorsten
puts determine_salesperson(
"age" => 25, "trait" => "rich")
# => adeslky
puts determine_salesperson(
"age" => 23, "trait" => "cheerful")
# => adeslky
puts determine_salesperson(
"age" => 25, "trait" => "maniac")
# => adeslky
puts determine_salesperson(
"age" => 44, "trait" => "maniac")
# => espadas
(original here)
Nothing prevents you from directly using the CSV “view” of a Google spreasheet like this :
table = Rufus::DecisionTable.new(
"http://spreadsheets.google.com/pub"+
"?key=pCkopoeZwCNsMWOVeDjR1TQ&"+
"joutput=csv&gid=0")
More info at http://rufus.rubyforge.org/rufus-decision
[...] ruby decision tables update (2008/01/28) : I’ve packaged those ruby decision tables into their own “rufus-decision” gem. More at http://jmettraux.wordpress.com/2008/01/28/rufus-decision-csv-decision-tables/ [...]
ruby decision tables « processi
January 28, 2008 at 8:11 am
[...] decision table quickstart Update : there is a new blog post covering this Ruby decision table subject, with updated [...]
ruby decision table quickstart « processi
February 20, 2008 at 1:25 am
[...] conversation that followed the meeting was extremely interesting, I was asked about integration of decision tables into business processes (as decision services via a CsvParticipant) : “too bad you [...]
Ruote presentation at Stockholm University « processi
October 15, 2008 at 7:07 am
[...] with 2 comments update : I implemented those decision tables as a ruby gem see this blog post. [...]
Decision Tables examples « processi
December 10, 2008 at 5:37 am