Class: VagrantPlugins::DevCommands::Util::JaroWinkler
- Inherits:
-
Object
- Object
- VagrantPlugins::DevCommands::Util::JaroWinkler
- Defined in:
- lib/vagrant/devcommands/util/jaro_winkler.rb
Overview
Jaro Winkler string distance
Adapted from: github.com/bbatsov/rubocop/blob/ec3123fc3454b080e1100e35480c6466d1240fff/lib/rubocop/string_util.rb
Constant Summary collapse
- BOOST_THRESHOLD =
0.7
- MAX_COMMON_PREFIX_LENGTH =
4
- SCALING_FACTOR =
0.1
Instance Method Summary collapse
- #distance ⇒ Object
-
#initialize(left, right) ⇒ JaroWinkler
constructor
A new instance of JaroWinkler.
Constructor Details
#initialize(left, right) ⇒ JaroWinkler
Returns a new instance of JaroWinkler.
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/vagrant/devcommands/util/jaro_winkler.rb', line 15 def initialize(left, right) @left = left.to_s @right = right.to_s if @left.size < @right.size @shorter = @left @longer = @right else @shorter = @right @longer = @left end end |
Instance Method Details
#distance ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/vagrant/devcommands/util/jaro_winkler.rb', line 28 def distance jaro_distance = compute_distance if jaro_distance >= BOOST_THRESHOLD jaro_distance += ( limited_common_prefix_length.to_f * SCALING_FACTOR.to_f * (1.0 - jaro_distance) ) end jaro_distance end |