Class: MatchMate::AddressMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/match-mate/address_matcher.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(address, other_address) ⇒ AddressMatcher

Returns a new instance of AddressMatcher.



15
16
17
18
# File 'lib/match-mate/address_matcher.rb', line 15

def initialize(address, other_address)
  @address = address.is_a?(MatchMate::Address) ? address : Address.new(address)
  @other_address = other_address.is_a?(MatchMate::Address) ? other_address : Address.new(other_address)
end

Class Method Details

.attributesObject



3
4
5
# File 'lib/match-mate/address_matcher.rb', line 3

def self.attributes
  @attributes ||= (MatchMate.config.address_weights || {}).deep_merge DEFAULTS[:address_weights]
end

.thresholdObject



7
8
9
# File 'lib/match-mate/address_matcher.rb', line 7

def self.threshold
  @threshold ||= MatchMate.config.address_threshold || DEFAULTS[:address_threshold]
end

.total_weightObject



11
12
13
# File 'lib/match-mate/address_matcher.rb', line 11

def self.total_weight
  @total_weight ||= attributes.values.sum { |config| config[:weight] }
end

Instance Method Details

#match?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/match-mate/address_matcher.rb', line 24

def match?
  score >= self.class.threshold
end

#scoreObject



20
21
22
# File 'lib/match-mate/address_matcher.rb', line 20

def score
  @score ||= calculate_score.round
end