<commit_before># == Schema Information
#
# Table name: form_submissions
#
#  id         :integer          not null, primary key
#  form_id    :integer
#  idx        :integer          default(0)
#  field_data :text
#  created_at :datetime
#  updated_at :datetime
#

class FormSubmission < ActiveRecord::Base

  # ------------------------------------------ Plugins

  include FormIdx

  # ------------------------------------------ Attributes

  serialize :field_data, Hash

  # ------------------------------------------ Associations

  belongs_to :form, :touch => true

  has_many :form_fields, :through => :form

  # ------------------------------------------ Scopes

  scope :desc, -> { order('created_at desc') }

  # ------------------------------------------ Callbacks

  after_create :send_response

  # ------------------------------------------ Instance Methods

  def title
    field_data[field_data.keys.first]
  end

  def send_notification
    form = self.form
    return false if form.notification_emails.blank?
    emails = form.notification_emails.split("\n").collect(&:strip)
    FormsMailer.new_submission(self, emails).deliver
  end

  def send_response
    form = self.form
    if form.email_subject.present? &&
      form.email_body.present? &&
      form.email_to_id.present?
        FormsMailer.response_message(
          self.field_data[form.email_to.slug],
          form
        ).deliver
    end
  end

  def respond_to?(method, include_private = false)
    return true if form_fields.collect(&:slug).include?(method.to_s)
    super
  end

  def method_missing(method, *arguments, &block)
    begin
      super
    rescue
      if !field_data[method.downcase.to_s].nil?
        field_data[method.downcase.to_s]
      elsif respond_to?(method)
        ""
      else
        super
      end
    end
  end

end
<commit_msg>fix a little buggy<commit_after># == Schema Information
#
# Table name: form_submissions
#
#  id         :integer          not null, primary key
#  form_id    :integer
#  idx        :integer          default(0)
#  field_data :text
#  created_at :datetime
#  updated_at :datetime
#

class FormSubmission < ActiveRecord::Base

  # ------------------------------------------ Plugins

  include FormIdx

  # ------------------------------------------ Attributes

  serialize :field_data, Hash

  # ------------------------------------------ Associations

  belongs_to :form, :touch => true

  # ------------------------------------------ Scopes

  scope :desc, -> { order('created_at desc') }

  # ------------------------------------------ Callbacks

  after_create :send_response

  # ------------------------------------------ Instance Methods

  def title
    field_data[field_data.keys.first]
  end

  def send_notification
    form = self.form
    return false if form.notification_emails.blank?
    emails = form.notification_emails.split("\n").collect(&:strip)
    FormsMailer.new_submission(self, emails).deliver
  end

  def send_response
    form = self.form
    if form.email_subject.present? &&
      form.email_body.present? &&
      form.email_to_id.present?
        FormsMailer.response_message(
          self.field_data[form.email_to.slug],
          form
        ).deliver
    end
  end

  def respond_to?(method, include_private = false)
    if !form.nil? && form.form_fields.collect(&:slug).include?(method.to_s)
      return true
    end
    super
  end

  def method_missing(method, *arguments, &block)
    begin
      super
    rescue
      if !field_data[method.downcase.to_s].nil?
        field_data[method.downcase.to_s]
      elsif respond_to?(method)
        ""
      else
        super
      end
    end
  end

end

{'fraction_non_alphanumeric': 0.21691973969631237, 'fraction_numerical': 0.0005422993492407809, 'mean_word_length': 1.6520488856937454, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, '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': '3802924', 'n_tokens_mistral': 1060, 'n_tokens_neox': 1034, 'n_words': 223}