lib/attr_similar.rb in attr_similar-0.0.0 vs lib/attr_similar.rb in attr_similar-0.0.1

- old
+ new

@@ -3,27 +3,17 @@ module AttrSimilar extend ActiveSupport::Concern module ClassMethods - def attr_similar(attributes) - self.similar_attributes = attributes + def attr_similar(threshold_or_thresholds, *attributes) + if threshold_or_thresholds.is_a?(Array) && threshold_or_thresholds.size != attributes.size + raise 'Threshold count must equal number of attributes' + end + define_method :find_first_similar do |scope| + AttrSimilar::SimilarityMatching.find_first_similar(scope, self, threshold_or_thresholds, attributes) + end end - - def similar_attributes - @@similar_attributes ||= [] - end - - def similar_attributes=(value) - @@similar_attributes = value - end - end - - included do - end - - def sample_method - AttrSimilar::SimilarityMatching.sample_method(self.class.similar_attributes) end end ActiveRecord::Base.send :include, AttrSimilar