github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

jmettraux / rufus-decision

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 15
    • 0
  • Source
  • Commits
  • Network (0)
  • Issues (0)
  • Downloads (3)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (3)
    • r1.2.0
    • r1.1.0
    • r1.0
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

CSV based Ruby decision tables — Read more

  cancel

http://rufus.rubyforge.org/rufus-decision

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

updated changelog. closes gh-1 
jmettraux (author)
Sun Sep 06 22:03:15 -0700 2009
commit  72e9e3b54d22c785dacb0a1ca06332f2e88e568d
tree    97f0ca096caa37e54d736f1f339da71706cfdf76
parent  39198fb6ab8b8d647e79e3bd4ac9f70e370bbf6f
rufus-decision /
name age
history
message
file CHANGELOG.txt Sun Sep 06 22:03:15 -0700 2009 updated changelog. closes gh-1 [jmettraux]
file CREDITS.txt Sun Sep 06 22:03:15 -0700 2009 updated changelog. closes gh-1 [jmettraux]
file LICENSE.txt Sun Apr 06 19:09:13 -0700 2008 first git commit [jmettraux]
file README.txt Sun Apr 26 16:39:13 -0700 2009 linking to intro blog post [jmettraux]
file Rakefile Sun Sep 06 21:32:41 -0700 2009 1.2.0 [jmettraux]
file TODO.txt Sun Sep 06 21:24:31 -0700 2009 made bounded match default for string_compare() [jmettraux]
directory bin/ Fri Apr 24 19:24:58 -0700 2009 - todo #25670 : :ruby_eval settable at table in... [jmettraux]
directory demo/ Sun Apr 26 16:39:13 -0700 2009 linking to intro blog post [jmettraux]
directory examples/ Sat Jun 14 06:13:15 -0700 2008 indent = 2 [jmettraux]
directory lib/ Sun Sep 06 21:54:57 -0700 2009 added 'unbounded' option [jmettraux]
directory test/ Sun Sep 06 21:54:57 -0700 2009 added 'unbounded' option [jmettraux]
README.txt
= rufus-decision


== getting it

  sudo gem install -y rufus-decision

or at

http://rubyforge.org/frs/?group_id=4812

== intro blog post

http://jmettraux.wordpress.com/2009/04/25/rufus-decision-11-ruby-decision-tables/

== usage

More info at http://rufus.rubyforge.org/rufus-decision/classes/Rufus/Decision/Table.html but here is a recap.

An example where a few rules determine which salesperson should interact with a customer with given characteristics.


  require 'rubygems'
  require 'rufus/decision'
  
  TABLE = Rufus::Decision::Table.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


More at Rufus::Decision::Table

Note that you can use a CSV table served over HTTP like in :

  
  require 'rubygems'
  require 'rufus/decision'
  
  TABLE = Rufus::DecisionTable.new(
    'http://spreadsheets.google.com/pub?key=pCkopoeZwCNsMWOVeDjR1TQ&output=csv')
  
  # the CSV is :
  #
  # in:weather,in:month,out:take_umbrella?
  #
  # raining,,yes
  # sunny,,no
  # cloudy,june,yes
  # cloudy,may,yes
  # cloudy,,no
  
  def take_umbrella? (weather, month=nil)
    h = TABLE.transform('weather' => weather, 'month' => month)
    h['take_umbrella?'] == 'yes'
  end
  
  puts take_umbrella?('cloudy', 'june')
    # => true
  
  puts take_umbrella?('sunny', 'june')
    # => false

In this example, the CSV table is the direction CSV representation of the Google spreadsheet at : 
http://spreadsheets.google.com/pub?key=pCkopoeZwCNsMWOVeDjR1TQ

WARNING though : use at your own risk. CSV loaded from untrusted locations may contain harmful code. The rufus-decision 
gem has an abstract tree checker integrated, it will check all the CSVs that contain calls in Ruby and raise a security 
error when possibly harmful code is spotted. Bullet vs Armor. Be warned.


== uninstalling it

    sudo gem uninstall -y rufus-decision


== dependencies

The gem 'rufus-dollar' (http://rufus.rubyforge.org/rufus-dollar) and the 'rufus-treechecker' gem 
(http://rufus.rubyforge.org/rufus-treechecker).


== mailing list

On the rufus-ruby list :

http://groups.google.com/group/rufus-ruby


== irc

irc.freenode.net #ruote


== issue tracker

http://rubyforge.org/tracker/?atid=18584&group_id=4812&func=browse


== source

http://github.com/jmettraux/rufus-decision

  git clone git://github.com/jmettraux/rufus-decision.git


== author

John Mettraux, jmettraux@gmail.com 
http://jmettraux.wordpress.com


== the rest of Rufus

http://rufus.rubyforge.org


== license

MIT

Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server