Class: RuboCop::StringUtil::Jaro

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop/string_util.rb

Overview

This class computes Jaro distance, which is a measure of similarity between two strings.

Direct Known Subclasses

JaroWinkler

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(a, b) ⇒ Jaro

Returns a new instance of Jaro.



21
22
23
24
25
26
27
28
29
# File 'lib/rubocop/string_util.rb', line 21

def initialize(a, b)
  if a.size < b.size
    @shorter = a
    @longer = b
  else
    @shorter = b
    @longer = a
  end
end

Instance Attribute Details

#longerObject (readonly)

Returns the value of attribute longer.



15
16
17
# File 'lib/rubocop/string_util.rb', line 15

def longer
  @longer
end

#shorterObject (readonly)

Returns the value of attribute shorter.



15
16
17
# File 'lib/rubocop/string_util.rb', line 15

def shorter
  @shorter
end

Class Method Details

.distance(*args) ⇒ Object



17
18
19
# File 'lib/rubocop/string_util.rb', line 17

def self.distance(*args)
  new(*args).distance
end

Instance Method Details

#distanceObject



31
32
33
# File 'lib/rubocop/string_util.rb', line 31

def distance
  @distance ||= compute_distance
end