module Eco module Data module FuzzyMatch class Results < Struct.new(:needle, :value, :raw_results) def results_with_false_positives relevant_results(methods: :jaro_winkler, threshold: 0.5) end def relevant_results(methods: order, threshold: 0.5) raw_results.select do |result| result.all_threshold?(methods, threshold) end.yield_self do |filtered| self.class.new(needle, value, filtered).tap do |results| results.order = methods end end end def order=(values) @order = [values].flatten.compact raw_results.each {|r| r.order = @order} end def order @order ||= [:words_ngrams, :dice] end def results raw_results.sort end def print msg = results.map do |result| result.print end.join("\n ") puts "'#{value}':\n " + msg end private def item_string(item, attr = self.method) return item if !item || item.is_a?(String) || !attr attr = attr.to_sym return item.send(attr) if item.respond_to?(attr) end end end end end