Class: OfacMatch
- Inherits:
-
Object
- Object
- OfacMatch
- Defined in:
- app/models/ofac_match.rb
Instance Attribute Summary collapse
-
#possible_hits ⇒ Object
readonly
Returns the value of attribute possible_hits.
Instance Method Summary collapse
-
#initialize(stats = {}) ⇒ OfacMatch
constructor
Intialize a Match object with a record hash of fields you want to match on.
-
#score(match_records) ⇒ Object
match_records is an array of hashes.
Constructor Details
#initialize(stats = {}) ⇒ OfacMatch
Intialize a Match object with a record hash of fields you want to match on. Each key in the hash, also has a data hash value for the weight, token, and type.
match = Ofac::Match.new({:name => {:weight => 10, :token => 'Kevin Tyll'},
:city => {:weight => 40, :token => 'Clearwater', },
:address => {:weight => 40, :token => '1234 Park St.', },
:zip => {:weight => 10, :token => '33759', :type => :number}})
data hash keys:
* <tt>data[:weight]</tt> - value to apply to the score if there is a match (Default is 100/number of keys in the record hash)
* <tt>data[:token]</tt> - string to match
* <tt>data[:match]</tt> - set from records hash
* <tt>data[:score]</tt> - output field
* <tt>data[:type]</tt> - the type of match that should be performed (valid values are +:sound+ | +:number+) (Default is +:sound+)
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/models/ofac_match.rb', line 19 def initialize(stats={}) @possible_hits = [] @stats = stats.dup weight = 100 weight = 100 / @stats.length if @stats.length > 0 @stats.each_value do |data| data[:weight] ||= weight data[:match] ||= '' data[:type] ||= :sound data[:score] ||= 0 data[:token] = data[:token].to_s.upcase end end |
Instance Attribute Details
#possible_hits ⇒ Object (readonly)
Returns the value of attribute possible_hits.
3 4 5 |
# File 'app/models/ofac_match.rb', line 3 def possible_hits @possible_hits end |
Instance Method Details
#score(match_records) ⇒ Object
match_records is an array of hashes.
The hash keys must match the record hash keys set when initialized.
score will return the highest score of all the records that are sent in match_records.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/models/ofac_match.rb', line 39 def score(match_records) score_results = Array.new unless match_records.empty? #place the match_records information #into our @stats hash match_records.each do |match| match.each do |key, value| @stats[key.to_sym][:match] = value.to_s.upcase end record_score = calculate_record score_results.push(record_score) @possible_hits << match.merge(:score => record_score) if record_score > 0 end score = score_results.max #take max score end @possible_hits.uniq! score ||= 0 end |