I am very new to Ruleby and couldn't find much documentation on the
web for this library.
I have written a very simple ruby module using the code here
http://github.com/codeaspects/ruleby/blob/master/examples/diagnosis.rb
The code resides in the lib directory of my Rails app.
module RuleEngine
require 'ruleby'
include Ruleby
class Patient
def initialize(age, bmi)
@age = age
@bmi = bmi
end
attr:age, true
attr:bmi, true
def tips
engine :engine do |e|
DiagnosisRulebook.new e do |r|
r.rules
end
e.assert self
e.match
end
return "done"
end
end
class DiagnosisRulebook < Ruleby::Rulebook
def rules
rule :age_greater_than_or_equal_to_50, [Patient, :p, m.age >=
50] do |v|
puts "age_greater_than_or_equal_to_50"
end
rule :age_greater_than_or_equal_to_65, [Patient, :p, m.age >=
65] do |v|
puts "age_greater_than_or_equal_to_65"
end
rule :bmi_less_than_19, [Patient, :p, m.bmi < 19] do |v|
puts "bmi_less_than_19"
end
rule :bmi_between_25_and_30, [Patient, :p, m.bmi(&c{|f| f >= 25
&& f < 30})] do |v|
puts "bmi_between_25_and_30"
end
end
end
end
Now on script console I do this:
include RuleEngine
p = Patient.new(21, 17)
p.tips
and the output is:
bmi_less_than_19
"done"
which is good
Now when i remove the first parameter which is age the bmi rule
doesn't get fired
p = Patient.new(nil, 17)
p.tips
and the output is:
"done"
I think there is something very basic that I am not doing in a right
manner.
Can anybody help ?
--
You received this message because you are subscribed to the Google Groups "Ruleby" group.
To post to this group, send email to rul...@googlegroups.com.
To unsubscribe from this group, send email to ruleby+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ruleby?hl=en.
Thanks again,
Joe
> > ruleby+un...@googlegroups.com<ruleby%2Bunsu...@googlegroups.com>