<commit_before>class Customer < ActiveRecord::Base
  belongs_to :provider
  belongs_to :address
  belongs_to :mobility
  belongs_to :created_by, :foreign_key => :created_by_id, :class_name=>'User'
  belongs_to :updated_by, :foreign_key => :updated_by_id, :class_name=>'User'
  accepts_nested_attributes_for :address

  normalize_attribute :first_name, :with=> [:squish, :titleize]
  normalize_attribute :last_name, :with=> [:squish, :titleize]
  normalize_attribute :middle_initial, :with=> [:squish, :upcase]

  default_scope :order => 'last_name, first_name, middle_initial'

  stampable :creator_attribute => :created_by_id, :updater_attribute => :updated_by_id

  def name
    if group
      return "(Group) %s" % first_name
    end
    if middle_initial.present?
      return "%s %s. %s" % [first_name, middle_initial, last_name]
    else
      return "%s %s " % [first_name, last_name]
    end
  end

  def age_in_years
    if birth_year.nil?
      return nil
    end
    today = Date.today
    years = today.year - birth_date.year #2011 - 1980 = 31
    if today.month < birth_year.month  || today.month == birth_year.month and today.day < birth_year.day #but 4/8 is before 7/3, so age is 30
      years -= 1
    end
    return years
  end
  
  def as_autocomplete
    { :label           => name, 
      :id              => id,
      :phone_number_1  => phone_number_1, 
      :phone_number_2  => phone_number_2,
      :mobility_notes  => mobility_notes,
      :address         => address.text,
      :address_id      => address.id,
      :private_notes   => private_notes,
      :group           => group
    }
  end

end<commit_msg>customers don't always have an address<commit_after>class Customer < ActiveRecord::Base
  belongs_to :provider
  belongs_to :address
  belongs_to :mobility
  belongs_to :created_by, :foreign_key => :created_by_id, :class_name=>'User'
  belongs_to :updated_by, :foreign_key => :updated_by_id, :class_name=>'User'
  accepts_nested_attributes_for :address

  normalize_attribute :first_name, :with=> [:squish, :titleize]
  normalize_attribute :last_name, :with=> [:squish, :titleize]
  normalize_attribute :middle_initial, :with=> [:squish, :upcase]

  default_scope :order => 'last_name, first_name, middle_initial'

  stampable :creator_attribute => :created_by_id, :updater_attribute => :updated_by_id

  def name
    if group
      return "(Group) %s" % first_name
    end
    if middle_initial.present?
      return "%s %s. %s" % [first_name, middle_initial, last_name]
    else
      return "%s %s " % [first_name, last_name]
    end
  end

  def age_in_years
    if birth_year.nil?
      return nil
    end
    today = Date.today
    years = today.year - birth_date.year #2011 - 1980 = 31
    if today.month < birth_year.month  || today.month == birth_year.month and today.day < birth_year.day #but 4/8 is before 7/3, so age is 30
      years -= 1
    end
    return years
  end
  
  def as_autocomplete
    if address.present?
      address_text = address.text 
      address_id = address.id 
    end

    { :label           => name, 
      :id              => id,
      :phone_number_1  => phone_number_1, 
      :phone_number_2  => phone_number_2,
      :mobility_notes  => mobility_notes,
      :address         => address_text,
      :address_id      => address_id,
      :private_notes   => private_notes,
      :group           => group
    }
  end

end
{'fraction_non_alphanumeric': 0.10428907168037603, 'fraction_numerical': 0.012338425381903642, 'mean_word_length': 2.945538818076477, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 41, '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': '7210838', 'n_tokens_mistral': 1190, 'n_tokens_neox': 1143, 'n_words': 275}