class OfacMatch

Attributes

possible_hits[R]

Public Class Methods

new(stats={}) click to toggle source

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/umber 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+)
# File lib/ofac/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

Public Instance Methods

score(match_records) click to toggle source

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.

# File lib/ofac/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