Hash in rule pattern

17 views
Skip to first unread message

mike

unread,
Apr 15, 2010, 12:53:01 PM4/15/10
to Ruleby
Hi,

Trying to use a hash in the pattern:

$LOAD_PATH << File.join(File.dirname(__FILE__), '../lib/')
require 'rubygems'
require 'ruleby'

include Ruleby

class DistReinvestEligibCodeRulebook < Ruleby::Rulebook

def rules

rule [ Hash, :cusip_hash, cusip_hash.
['distribution_reinvestment_eligibility_code'] == 'yes', cusip_hash.
['distribution_reinvestment_load_code'] == nil ] do |v|

#v[:invalid_dp_array] <<
['distribution_reinvestment_load_code', ['yes','no'] ]
puts "Invalid, if eligibility_code == yes, load_code can not
be empty"
end

end #end of rules
end

cusip_hash =
{
'distribution_reinvestment_eligibility_code' => 'yes',
'distribution_reinvestment_load_code' => nil
}

engine :engine do |e|

DistReinvestEligibCodeRulebook.new e do |r|
r.rules
end

e.assert cusip_hash

e.match

end

So when I run I get:

main.rb:43: undefined method
`distribution_reinvestment_eligibility_code' for #<Hash:0x13bc440>
(NoMethodError)
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in
`gem_original_require'
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in
`require'

My cusip_hash has 800 values, so I'm trying to avoid converting the
cusip_hash into a cusip class like most of the Ruleby examples use....

I tried changing cusip_hash.
['distribution_reinvestment_eligibility_code'] to
cusip_hash.fetch('distribution_reinvestment_eligibility_code'), did
not work, found other post in this group that indicated that the rule
can't use a method that takes parameters.....

Any suggestion\ ideas \ comments would be much appreciated

Thanks,

Mike

Reply all
Reply to author
Forward
0 new messages