<commit_before>class BhsiApplication < ActiveRecord::Base

  include SearchSortPaginate
  include PdfCreator

  MAX_MAKES_SOCIAL_INNOVATION_WORDS = 300
  MAX_INSPIRATION_WORDS             = 500
  MAX_SUSTAINABITILITY_MODEL_WORDS  = 600
  MAX_IMPROVEMENTS_WORDS            = 400
  MAX_DISTINGUISH_YOURSELF_WORDS    = 600
  MAX_MAJOR_SOURCES_INCOME_WORDS    = 300
  MAX_IMPACT_WORDS                  = 500
  MAX_OBSTACLES_NEEDS_WORDS         = 600
  BIRTHDATE_LIMIT                   = "10/12/1978"
  BIRTHDATE_FORMAT                  = "%m/%d/%Y"
  MAX_PDF_FILE_SIZE                 = 5

  has_attached_file :pdf,                   :path => "applications/bhsi/pdfs/:id/:filename"
  has_attached_file :previous_budget,       :path => "applications/bhsi/pdfs/:id/:filename"
  has_attached_file :current_budget,        :path => "applications/bhsi/pdfs/:id/:filename"
  has_attached_file :press_clipping_1,      :path => "applications/bhsi/pdfs/:id/:filename"
  has_attached_file :press_clipping_2,      :path => "applications/bhsi/pdfs/:id/:filename"
  has_attached_file :press_clipping_3,      :path => "applications/bhsi/pdfs/:id/:filename"
  has_attached_file :venture_standard_deck, :path => "applications/bhsi/pdfs/:id/:filename"

  has_one :bhsi_longtext, :dependent => :destroy
  # we have a polymorphic relationship with notes
  has_many :notes, :as => :asset

  accepts_nested_attributes_for :bhsi_longtext

  validates :first_name,                :presence => true
  validates :last_name,                 :presence => true
  validates :address1,                  :presence => true
  validates :city,                      :presence => true
  validates :state,                     :presence => true
  validates :country,                   :presence => true
  validates :phone_number,              :presence => true, :length => { :minimum => 8 }
  validates :zipcode,                   :presence => true
  validates :email,                     :presence => true, :email => true
  validates :gender,                    :presence => true
  validates :birthdate,                 :presence => true
  validates :title,                     :presence => true
  validates :social_venture_name,       :presence => true
  validates :legal_structure,           :presence => true
  validates :url,                       :presence => true
  validates :twitter_handle,            :presence => true
  validates :video_url,                 :presence => true
  validates :applied_before,            :presence => true
  validates :reference_1_name,          :presence => true
  validates :reference_1_relationship,  :presence => true
  validates :reference_1_phone,         :presence => true, :length => { :minimum => 8 }
  validates :reference_1_email,         :presence => true, :email => true
  validates :reference_2_name,          :presence => true
  validates :reference_2_relationship,  :presence => true
  validates :reference_2_phone,         :presence => true, :length => { :minimum => 8 }
  validates :reference_2_email,         :presence => true, :email => true
  validates :agreement_accepeted,       :acceptance => { :accept => true }
  validates :total_budget_current_year, :presence => true
  validates :org_founder,               :inclusion => { :in => ["yes", "no"] }, :allow_nil => false
  validates :org_join_point,            :presence => true, :if => Proc.new { |ba| ba.org_founder == "no" }
  validates :sustainability_model,      :presence => true

  validate :limit_birthdate, :if => Proc.new { |b| b.birthdate.present? }

  validates_attachment_presence :previous_budget
  validates_attachment_presence :current_budget
  validates_attachment_presence :venture_standard_deck

  validates_format_of :previous_budget_file_name,       :with => %r{\.pdf$}i, :message => "file must be in .pdf format", :if => Proc.new { |u| u.previous_budget.present? }
  validates_format_of :current_budget_file_name,        :with => %r{\.pdf$}i, :message => "file must be in .pdf format", :if => Proc.new { |u| u.current_budget.present? }
  validates_format_of :venture_standard_deck_file_name, :with => %r{\.pdf$}i, :message => "file must be in .pdf format", :if => Proc.new { |u| u.venture_standard_deck.present? }
  validates_format_of :press_clipping_1_file_name,      :with => %r{\.pdf$}i, :message => "file must be in .pdf format", :if => Proc.new { |u| u.press_clipping_1.present? }
  validates_format_of :press_clipping_2_file_name,      :with => %r{\.pdf$}i, :message => "file must be in .pdf format", :if => Proc.new { |u| u.press_clipping_2.present? }
  validates_format_of :press_clipping_3_file_name,      :with => %r{\.pdf$}i, :message => "file must be in .pdf format", :if => Proc.new { |u| u.press_clipping_3.present? }

  validates_attachment_size :previous_budget,       :less_than => MAX_PDF_FILE_SIZE.megabytes
  validates_attachment_size :current_budget,        :less_than => MAX_PDF_FILE_SIZE.megabytes
  validates_attachment_size :press_clipping_1,      :less_than => MAX_PDF_FILE_SIZE.megabytes
  validates_attachment_size :press_clipping_2,      :less_than => MAX_PDF_FILE_SIZE.megabytes
  validates_attachment_size :press_clipping_3,      :less_than => MAX_PDF_FILE_SIZE.megabytes
  validates_attachment_size :venture_standard_deck, :less_than => MAX_PDF_FILE_SIZE.megabytes

  validates :makes_social_innovation, :presence => true, :length => {
    :maximum   => MAX_MAKES_SOCIAL_INNOVATION_WORDS,
    :tokenizer => lambda { |str| str.scan(/\w+/) },<commit_msg>Validation for organization founder<commit_after>class BhsiApplication < ActiveRecord::Base

  include SearchSortPaginate
  include PdfCreator

  MAX_MAKES_SOCIAL_INNOVATION_WORDS = 300
  MAX_INSPIRATION_WORDS             = 500
  MAX_SUSTAINABITILITY_MODEL_WORDS  = 600
  MAX_IMPROVEMENTS_WORDS            = 400
  MAX_DISTINGUISH_YOURSELF_WORDS    = 600
  MAX_MAJOR_SOURCES_INCOME_WORDS    = 300
  MAX_IMPACT_WORDS                  = 500
  MAX_OBSTACLES_NEEDS_WORDS         = 600
  BIRTHDATE_LIMIT                   = "10/12/1978"
  BIRTHDATE_FORMAT                  = "%m/%d/%Y"
  MAX_PDF_FILE_SIZE                 = 5

  has_attached_file :pdf,                   :path => "applications/bhsi/pdfs/:id/:filename"
  has_attached_file :previous_budget,       :path => "applications/bhsi/pdfs/:id/:filename"
  has_attached_file :current_budget,        :path => "applications/bhsi/pdfs/:id/:filename"
  has_attached_file :press_clipping_1,      :path => "applications/bhsi/pdfs/:id/:filename"
  has_attached_file :press_clipping_2,      :path => "applications/bhsi/pdfs/:id/:filename"
  has_attached_file :press_clipping_3,      :path => "applications/bhsi/pdfs/:id/:filename"
  has_attached_file :venture_standard_deck, :path => "applications/bhsi/pdfs/:id/:filename"

  has_one :bhsi_longtext, :dependent => :destroy
  # we have a polymorphic relationship with notes
  has_many :notes, :as => :asset

  accepts_nested_attributes_for :bhsi_longtext

  validates :first_name,                :presence => true
  validates :last_name,                 :presence => true
  validates :address1,                  :presence => true
  validates :city,                      :presence => true
  validates :state,                     :presence => true
  validates :country,                   :presence => true
  validates :phone_number,              :presence => true, :length => { :minimum => 8 }
  validates :zipcode,                   :presence => true
  validates :email,                     :presence => true, :email => true
  validates :gender,                    :presence => true
  validates :birthdate,                 :presence => true
  validates :title,                     :presence => true
  validates :social_venture_name,       :presence => true
  validates :legal_structure,           :presence => true
  validates :url,                       :presence => true
  validates :twitter_handle,            :presence => true
  validates :video_url,                 :presence => true
  validates :applied_before,            :presence => true
  validates :reference_1_name,          :presence => true
  validates :reference_1_relationship,  :presence => true
  validates :reference_1_phone,         :presence => true, :length => { :minimum => 8 }
  validates :reference_1_email,         :presence => true, :email => true
  validates :reference_2_name,          :presence => true
  validates :reference_2_relationship,  :presence => true
  validates :reference_2_phone,         :presence => true, :length => { :minimum => 8 }
  validates :reference_2_email,         :presence => true, :email => true
  validates :agreement_accepeted,       :acceptance => { :accept => true }
  validates :total_budget_current_year, :presence => true
  validates :org_founder,               :inclusion => { :in => ["Yes", "No"] }, :allow_nil => false
  validates :org_join_point,            :presence => true, :if => Proc.new { |ba| ba.org_founder == "No" }
  validates :sustainability_model,      :presence => true

  validate :limit_birthdate, :if => Proc.new { |b| b.birthdate.present? }

  validates_attachment_presence :previous_budget
  validates_attachment_presence :current_budget
  validates_attachment_presence :venture_standard_deck

  validates_format_of :previous_budget_file_name,       :with => %r{\.pdf$}i, :message => "file must be in .pdf format", :if => Proc.new { |u| u.previous_budget.present? }
  validates_format_of :current_budget_file_name,        :with => %r{\.pdf$}i, :message => "file must be in .pdf format", :if => Proc.new { |u| u.current_budget.present? }
  validates_format_of :venture_standard_deck_file_name, :with => %r{\.pdf$}i, :message => "file must be in .pdf format", :if => Proc.new { |u| u.venture_standard_deck.present? }
  validates_format_of :press_clipping_1_file_name,      :with => %r{\.pdf$}i, :message => "file must be in .pdf format", :if => Proc.new { |u| u.press_clipping_1.present? }
  validates_format_of :press_clipping_2_file_name,      :with => %r{\.pdf$}i, :message => "file must be in .pdf format", :if => Proc.new { |u| u.press_clipping_2.present? }
  validates_format_of :press_clipping_3_file_name,      :with => %r{\.pdf$}i, :message => "file must be in .pdf format", :if => Proc.new { |u| u.press_clipping_3.present? }

  validates_attachment_size :previous_budget,       :less_than => MAX_PDF_FILE_SIZE.megabytes
  validates_attachment_size :current_budget,        :less_than => MAX_PDF_FILE_SIZE.megabytes
  validates_attachment_size :press_clipping_1,      :less_than => MAX_PDF_FILE_SIZE.megabytes
  validates_attachment_size :press_clipping_2,      :less_than => MAX_PDF_FILE_SIZE.megabytes
  validates_attachment_size :press_clipping_3,      :less_than => MAX_PDF_FILE_SIZE.megabytes
  validates_attachment_size :venture_standard_deck, :less_than => MAX_PDF_FILE_SIZE.megabytes

  validates :makes_social_innovation, :presence => true, :length => {
    :maximum   => MAX_MAKES_SOCIAL_INNOVATION_WORDS,
    :tokenizer => lambda { |str| str.scan(/\w+/) },
{'fraction_non_alphanumeric': 0.11349972672617963, 'fraction_numerical': 0.010384405173984331, 'mean_word_length': 3.1618650492797573, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 167, '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': '1337902', 'n_tokens_mistral': 3748, 'n_tokens_neox': 3591, 'n_words': 723}