Sha256: ee75a11749d53e2e37b64915a6fe999aa41831da7167e4ed872f8fd65fb68ab2

Contents?: true

Size: 1.8 KB

Versions: 1

Compression:

Stored size: 1.8 KB

Contents

# China Mobile Phone Number 是中国移动电话号码。

class Unidom::Contact::China::MobilePhoneNumber < ActiveRecord::Base

  FORMAT_VALIDATION_REGEX = /\A1[3-9]\d{9}\z/

  self.table_name = 'unidom_china_mobile_phone_numbers'

  include Unidom::Common::Concerns::ModelExtension

  validates :phone_number,                  presence: true, length: { is: self.columns_hash['phone_number'].limit                  }, numericality: { integer_only: true }, format: FORMAT_VALIDATION_REGEX
  validates :network_identification_number, presence: true, length: { is: self.columns_hash['network_identification_number'].limit }, numericality: { integer_only: true }
  validates :serial_number,                 presence: true, length: { is: self.columns_hash['serial_number'].limit                 }, numericality: { integer_only: true }
  validates :area_code,                     numericality: { integer_only: true }

  has_many :contact_subscription, class_name: 'Unidom::Contact::ContactSubscription', as: :contact  

  scope :phone_number_is,                  ->(phone_number)                  { where phone_number:                  phone_number                  }
  scope :network_identification_number_is, ->(network_identification_number) { where network_identification_number: network_identification_number }
  scope :area_code_is,                     ->(area_code)                     { where area_code:                     area_code                     }
  scope :serial_number_is,                 ->(serial_number)                 { where serial_number:                 phone_number                  }

  before_validation do
    self.network_identification_number = self.phone_number[0..2]
    self.area_code                     = self.phone_number[3..6]
    self.serial_number                 = self.phone_number[7..10]
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
unidom-contact-china-0.3 app/models/unidom/contact/china/mobile_phone_number.rb