class RecordLinkage::ObjectComparer::Matcher
Matcher
objects represent how to handle individual rules to compare one field to another
Attributes
property1[R]
property2[R]
Public Class Methods
match_block_from_definition(definition)
click to toggle source
# File lib/record_linkage/object_comparer.rb, line 66 def self.match_block_from_definition(definition) case definition when String, Symbol if !Matchers.respond_to?("#{definition}_matcher") fail ArgumentError, "Matcher `#{definition}` is not defined" end Matchers.method("#{definition}_matcher") when Proc then definition else fail ArgumentError, "Invalid matcher definition: #{matcher.inspect}" end end
new(property1, property2, definition, options = {})
click to toggle source
# File lib/record_linkage/object_comparer.rb, line 49 def initialize(property1, property2, definition, options = {}) @property1 = property1 @property2 = property2 @block = self.class.match_block_from_definition(definition) @options = options end
Public Instance Methods
score_objects(object1, object2, default_threshold, default_weight)
click to toggle source
# File lib/record_linkage/object_comparer.rb, line 56 def score_objects(object1, object2, default_threshold, default_weight) value1 = object1.send(@property1) value2 = object2.send(@property2) threshold = @options[:threshold] || default_threshold weight = @options[:weight] || default_weight @block.call(value1, value2, threshold: threshold) * weight end