<commit_before>require 'array_logic'
module Qwester
  class RuleSet < ActiveRecord::Base
    attr_accessible :title, :description, :answers, :url, :rule, :answer_ids, :link_text, :warning_id

    before_save :keep_answers_in_step_with_rule

    DEFAULT_RULE_JOIN = 'or'
    ANSWERS_LIMIT = 10

    has_and_belongs_to_many(
      :answers, 
      :uniq => true,
      :join_table => :qwester_answers_rule_sets
    )
    accepts_nested_attributes_for :answers

    has_many(
      :questions,
      :through => :answers
    )

    validate :check_rule_is_valid

    validates :title, :presence => true
    validates :url, :presence => true


    def self.matching(answers)
      all.collect{|rule_set| rule_set if rule_set.match(answers)}.compact
    end

    def match(answers_to_check = nil)
      return unless answers_to_check and !answers_to_check.empty?
      generate_default_rule && save
      logic.match(answers_to_check)
    end<commit_msg>Simplifies matching method.<commit_after>require 'array_logic'
module Qwester
  class RuleSet < ActiveRecord::Base
    attr_accessible :title, :description, :answers, :url, :rule, :answer_ids, :link_text, :warning_id

    before_save :keep_answers_in_step_with_rule

    DEFAULT_RULE_JOIN = 'or'
    ANSWERS_LIMIT = 10

    has_and_belongs_to_many(
      :answers, 
      :uniq => true,
      :join_table => :qwester_answers_rule_sets
    )
    accepts_nested_attributes_for :answers

    has_many(
      :questions,
      :through => :answers
    )

    validate :check_rule_is_valid

    validates :title, :presence => true
    validates :url, :presence => true


    def self.matching(answers)
      all.select{|rule_set| rule_set.match(answers)}
    end

    def match(answers_to_check = nil)
      return unless answers_to_check and !answers_to_check.empty?
      generate_default_rule && save
      logic.match(answers_to_check)
    end
{'fraction_non_alphanumeric': 0.08778424114225278, 'fraction_numerical': 0.0021152829190904283, 'mean_word_length': 3.494061757719715, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2337169', 'n_tokens_mistral': 692, 'n_tokens_neox': 638, 'n_words': 125}