Getting results out of the rules

6 views
Skip to first unread message

mobilemike

unread,
Feb 19, 2010, 11:36:19 PM2/19/10
to Ruleby
I know I've got the basic idea of how Ruleby works understood, because
I have a gotten a basic version of my needs up and running. Now that
I'm trying to really productionalize it, I'm getting a bit stuck.

So, I have a set of rules that are all designed to validate a set of
compliance rules in my dataset. I don't want Ruleby to take any action
on the data, just report back violations to my pre defined rules.
Example:

class Dog
attr_accessor :legs
attr_accessor :spots
end

class DogRulebook < Ruleby::Rulebook
def dog_issues
rule [ Dog, :d, m.spots == 2, m.legs.not== 4] do |v|
puts "Dogs with two spots must have 4 legs"
end
end

Now that I need to move beyond the puts and start collecting real
information into an array, or into an instance of a class built just
to hold and modify rule violations, I can't figure out the next move.
I think, fundamentally, I find the whole thing a black box. I don't
really understand the scope that the matching occurs in. How would I
get data out of the class, i.e.:

class DogRulebook < Ruleby::Rulebook
def dog_issues
rule [ Dog, :d, m.spots == 2, m.legs.not== 4] do |v|
array_that_holds_all_the_violations << "Dogs with two spots must
have 4 legs"
end
end

Also, and probably more the direction I'm interesting in heading, what
about passing data in and out:

array_with_data_that_will_get_more = ['x', 'y']

class DogRulebook < Ruleby::Rulebook
def dog_issues
rule [ Dog, :d, m.spots == 2, m.legs.not== 4] do |v|
array_with_data_that_will_get_more << "Dogs with two spots must
have 4 legs"
end
end

Is this even the correct way of using the module? Am I only supposed
to use facts I've asserted and manipulate only those objects? If so,
do I just pass in this array as a fact? How do I get it out again? I'm
I _completely_ off base trying to use Ruleby like this for data
validation? Oi.

Well, if anyone understands the point at which I'm stuck, and knows of
some additional documentation to help me get past this point, I'd
greatly appreciate it.

- Mike Karolow

Matt Smith

unread,
Feb 21, 2010, 5:52:15 AM2/21/10
to rul...@googlegroups.com
Hi Mike,

I believe what you are looking for is the retrieve method on the engine object.  It will return all facts of a certain type as an array.  So you would need to assert those objects as facts in order to be able to retrieve them.

So in your action you would assert a fact containing the info you wanted out of the engine and then retrieve that info from the engine after the match cycle.

I hope that helps.

Thanks,

Matt


--
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.


mobilemike

unread,
Feb 21, 2010, 2:01:05 PM2/21/10
to Ruleby
That sounds exactly like the missing piece. I'll report back if this
solves the problem for me.

> > ruleby+un...@googlegroups.com<ruleby%2Bunsu...@googlegroups.com>

Reply all
Reply to author
Forward
0 new messages