<commit_before>class Lead < ActiveRecord::Base

  before_create :assign_location_from_zip
# ###############################################################################
# Relationship betweer User & Lead, through Order
# ###############################################################################
  has_many :reverse_orders, foreign_key: "selected_id", 
                                   class_name: "Order",
                                   dependent: :destroy
  has_many :selectors, through: :reverse_orders, source: :selector
  attr_writer :current_step

  # :::::::::::::: VALIDATIONS :::::::::::::::::::

  validates :business_type, presence: true
  validates :time, presence: true
  validates :description, presence: true
  validates :zip, presence: true, length: { is: 4 } 
  validates :email, presence: true
  validates :phone, presence: true
  # validates :name, presence: true


  def assign_location_from_zip
    if self.zip > 999 && self.zip < 1999
      self.location = "Ljubljana"
    elsif self.zip > 1999 && self.zip < 2999
      self.location = "Maribor"
    elsif self.zip > 2999 && self.zip < 3999
      self.location = "Celje"<commit_msg>Add before_safe to Lead model<commit_after>class Lead < ActiveRecord::Base

  before_create :assign_location_from_zip
  before_save :assign_location_from_zip
# ###############################################################################
# Relationship betweer User & Lead, through Order
# ###############################################################################
  has_many :reverse_orders, foreign_key: "selected_id", 
                                   class_name: "Order",
                                   dependent: :destroy
  has_many :selectors, through: :reverse_orders, source: :selector
  attr_writer :current_step

  # :::::::::::::: VALIDATIONS :::::::::::::::::::

  validates :business_type, presence: true
  validates :time, presence: true
  validates :description, presence: true
  validates :zip, presence: true, length: { is: 4 } 
  validates :email, presence: true
  validates :phone, presence: true
  # validates :name, presence: true


  def assign_location_from_zip
    if self.zip > 999 && self.zip < 1999
      self.location = "Ljubljana"
    elsif self.zip > 1999 && self.zip < 2999
      self.location = "Maribor"
    elsif self.zip > 2999 && self.zip < 3999
      self.location = "Celje"
{'fraction_non_alphanumeric': 0.23536789297658864, 'fraction_numerical': 0.020066889632107024, 'mean_word_length': 3.738613861386139, 'pattern_counts': {'":': 0, '<': 11, '<?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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6298902', 'n_tokens_mistral': 692, 'n_tokens_neox': 621, 'n_words': 169}