Class: FuzzyMatch::Score

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/fuzzy_match/score.rb,
lib/fuzzy_match/score/amatch.rb,
lib/fuzzy_match/score/pure_ruby.rb

Direct Known Subclasses

Amatch, PureRuby

Defined Under Namespace

Classes: Amatch, PureRuby

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str1, str2) ⇒ Score

Returns a new instance of Score.



11
12
13
14
# File 'lib/fuzzy_match/score.rb', line 11

def initialize(str1, str2)
  @str1 = str1.downcase
  @str2 = str2.downcase
end

Instance Attribute Details

#str1Object (readonly)

Returns the value of attribute str1.



8
9
10
# File 'lib/fuzzy_match/score.rb', line 8

def str1
  @str1
end

#str2Object (readonly)

Returns the value of attribute str2.



9
10
11
# File 'lib/fuzzy_match/score.rb', line 9

def str2
  @str2
end

Instance Method Details

#<=>(other) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/fuzzy_match/score.rb', line 20

def <=>(other)
  a = dices_coefficient_similar
  b = other.dices_coefficient_similar
  if a.nan? or b.nan? or (by_dices_coefficient = (a <=> b)) == 0
    levenshtein_similar <=> other.levenshtein_similar
  else
    by_dices_coefficient
  end
end

#inspectObject



16
17
18
# File 'lib/fuzzy_match/score.rb', line 16

def inspect
  %{(dice=#{"%0.5f" % dices_coefficient_similar},lev=#{"%0.5f" % levenshtein_similar})}
end