Class: VagrantPlugins::DevCommands::Util::JaroWinkler

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant/devcommands/util/jaro_winkler.rb

Overview

Constant Summary collapse

BOOST_THRESHOLD =
0.7
MAX_COMMON_PREFIX_LENGTH =
4
SCALING_FACTOR =
0.1

Instance Method Summary collapse

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

#distanceObject



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