Class: MatchMate::AddressMatcher
- Inherits:
-
Object
- Object
- MatchMate::AddressMatcher
- Defined in:
- lib/match-mate/address_matcher.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(address, other_address) ⇒ AddressMatcher
constructor
A new instance of AddressMatcher.
- #match? ⇒ Boolean
- #score ⇒ Object
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
.attributes ⇒ Object
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 |
.threshold ⇒ Object
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_weight ⇒ Object
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
24 25 26 |
# File 'lib/match-mate/address_matcher.rb', line 24 def match? score >= self.class.threshold end |
#score ⇒ Object
20 21 22 |
# File 'lib/match-mate/address_matcher.rb', line 20 def score @score ||= calculate_score.round end |