Sha256: 6ecf97a80a2a72d7c7198fcb9713fff1be47785dfe67b94e40bcd09907bc3393

Contents?: true

Size: 829 Bytes

Versions: 8

Compression:

Stored size: 829 Bytes

Contents

# == Schema Information
#
# Table name: phones
#
#  id         :integer          not null, primary key
#  contact_id :integer
#  phone_no   :string(14)
#  ext        :string(10)
#  phone_type :string(20)
#  created_at :datetime
#  updated_at :datetime
#

module CgAppBase
  class Phone < ActiveRecord::Base
    include AttributesNormalizer

    belongs_to :contact
    has_paper_trail
    validates :phone_no, :phone_type, :presence => true

    before_save :format_phone_no

    def format_phone_no
      self.phone_no = self.phone_no.tr('^0-9', '').strip
    end

    def short_phone_no
      area_code_right_indx = self.phone_no.size - 8
      return self.phone_no unless area_code_right_indx > -1

      area_code_right_indx = 2 if area_code_right_indx > 2
      self.phone_no[(area_code_right_indx + 1)..9]
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
cg_app_base-1.1.1 app/models/cg_app_base/phone.rb
cg_app_base-1.0.78 app/models/cg_app_base/phone.rb
cg_app_base-1.0.62 app/models/cg_app_base/phone.rb
cg_app_base-1.0.56 app/models/cg_app_base/phone.rb
cg_app_base-1.0.55 app/models/cg_app_base/phone.rb
cg_app_base-1.0.54 app/models/cg_app_base/phone.rb
cg_app_base-1.0.52 app/models/cg_app_base/phone.rb
cg_app_base-1.0.51 app/models/cg_app_base/phone.rb