<commit_before>class DependencyCondition < ActiveRecord::Base
  unloadable
  include Surveyor::Models::DependencyConditionMethods


  # overriding the to_hash method to add support for:
  # 
  #    condition_X :q_name, '==', {:string_value => '', :answer_reference => '1'}
  #
  # in the original implementation this doesn't work because a
  # blank response is nil, rather than ""
  def to_hash(response_set)

    if ['==', '!='].include?(operator) && string_value == ""
      is_blank = true

      response_set.responses.where(answer_id: answer).each do |response|
        is_blank = false unless response.string_value.blank?
      end

      flip = operator == '!='
      return {rule_key.to_sym => flip ? !is_blank : is_blank}

    else
      super response_set

    end
  end
end<commit_msg>nicer syntax for dependency condition hook<commit_after>class DependencyCondition < ActiveRecord::Base
  unloadable
  include Surveyor::Models::DependencyConditionMethods


  # overriding the to_hash method to add support for:
  # 
  #    condition_X :q_name, '==', {:string_value => '', :answer_reference => '1'}
  #
  # in the original implementation this doesn't work because a
  # blank response is nil, rather than ""
  def to_hash(response_set)
    if ['==', '!='].include?(operator) && string_value == ""
      is_blank = true

      response_set.responses.where(answer_id: answer).each do |response|
        is_blank = false unless response.string_value.blank?
      end

      flip = operator == '!='
      
      {rule_key.to_sym => flip ^ is_blank}
    else
      super response_set
    end
  end
end
{'fraction_non_alphanumeric': 0.11318407960199005, 'fraction_numerical': 0.0012437810945273632, 'mean_word_length': 3.3841961852861036, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '3498557', 'n_tokens_mistral': 492, 'n_tokens_neox': 472, 'n_words': 128}