class Eco::Data::FuzzyMatch::Score
Public Instance Methods
increase(value = 1)
click to toggle source
# File lib/eco/data/fuzzy_match/score.rb, line 17 def increase(value = 1) self.score += value raise "Score #{self.score} (increase: #{value}) can't be greater than total #{self.total}" if self.score > self.total self.score end
increase_total(value)
click to toggle source
# File lib/eco/data/fuzzy_match/score.rb, line 23 def increase_total(value) self.total += value end
merge(scr)
click to toggle source
Merges 2 Score
instance objects
# File lib/eco/data/fuzzy_match/score.rb, line 34 def merge(scr) Score.new(*values_at(:score, :total)).merge!(scr) end
merge!(scr)
click to toggle source
# File lib/eco/data/fuzzy_match/score.rb, line 38 def merge!(scr) raise "Expecting Score object. Given: #{scr.class}" unless scr.is_a?(Score) increase_total(scr.total) increase(scr.score) self end
percent(decimals = 3)
click to toggle source
# File lib/eco/data/fuzzy_match/score.rb, line 13 def percent(decimals = 3) (100 * ratio).round(decimals) end
ratio(decimals = 6)
click to toggle source
# File lib/eco/data/fuzzy_match/score.rb, line 6 def ratio(decimals = 6) tot = self.total; sc = self.score tot = tot && tot > 0 ? tot : 1 sc = sc && sc > 0 ? sc : 0 (sc.to_f / tot).round(decimals) end
values_at(*keys)
click to toggle source
# File lib/eco/data/fuzzy_match/score.rb, line 27 def values_at(*keys) keys.map do |key| self.send(key) if self.respond_to?(key) end end