<commit_before>module Humanizer
  
  def self.included(base)
    base.extend(ClassMethods)
  end
  
  attr_accessor :humanizer_answer
  attr_writer :humanizer_question_id

  def humanizer_question
    humanizer_questions[humanizer_question_id.to_i]["question"]
  end
  
  def humanizer_question_id
    @humanizer_question_id ||= Kernel.rand(humanizer_questions.count)
  end
  
  def humanizer_correct_answer?
    humanizer_answer && humanizer_answers_for_id(humanizer_question_id).include?(humanizer_answer.downcase)
  end

  private
  
  def humanizer_questions
    @humanizer_questions ||= I18n.translate("humanizer.questions")
  end

  def humanizer_answers_for_id(id)
    question = humanizer_questions[id.to_i]
    Array(question["answer"] || question["answers"]).map { |a| a.to_s.downcase }
  end

  def humanizer_check_answer
    errors[:base] << I18n.translate("humanizer.validation.error") unless humanizer_correct_answer?
  end
  
  module ClassMethods
    
    def require_human_on(validate_on, opts = {})
      opts[:on] = validate_on
      validate :humanizer_check_answer,  opts
    end
    
  end
  
end<commit_msg>Changed errors[:base] in humanizer.rb to errors[:humanizer_answer] to add compatibility with formtastic inline errors.<commit_after>module Humanizer
  
  def self.included(base)
    base.extend(ClassMethods)
  end
  
  attr_accessor :humanizer_answer
  attr_writer :humanizer_question_id

  def humanizer_question
    humanizer_questions[humanizer_question_id.to_i]["question"]
  end
  
  def humanizer_question_id
    @humanizer_question_id ||= Kernel.rand(humanizer_questions.count)
  end
  
  def humanizer_correct_answer?
    humanizer_answer && humanizer_answers_for_id(humanizer_question_id).include?(humanizer_answer.downcase)
  end

  private
  
  def humanizer_questions
    @humanizer_questions ||= I18n.translate("humanizer.questions")
  end

  def humanizer_answers_for_id(id)
    question = humanizer_questions[id.to_i]
    Array(question["answer"] || question["answers"]).map { |a| a.to_s.downcase }
  end

  def humanizer_check_answer
    errors[:humanizer_answer] << I18n.translate("humanizer.validation.error") unless humanizer_correct_answer?
  end
  
  module ClassMethods
    
    def require_human_on(validate_on, opts = {})
      opts[:on] = validate_on
      validate :humanizer_check_answer,  opts
    end
    
  end
  
end
{'fraction_non_alphanumeric': 0.08413967185527976, 'fraction_numerical': 0.0033655868742111907, 'mean_word_length': 4.441647597254004, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '2831955', 'n_tokens_mistral': 808, 'n_tokens_neox': 779, 'n_words': 129}