processi

about processes and engines

‘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

Written by John Mettraux

January 28, 2008 at 8:04 am

Posted in csv, decision, ruby, rufus

4 Responses

Subscribe to comments with RSS.

  1. […] 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/ […]

  2. […] decision table quickstart Update : there is a new blog post covering this Ruby decision table subject, with updated […]

  3. […] 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 […]

  4. […] with 2 comments update : I implemented those decision tables as a ruby gem see this blog post. […]


Comments are closed.

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: