Class: Ronin::DB::PhoneNumber
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Ronin::DB::PhoneNumber
- Includes:
- Model, Model::Importable
- Defined in:
- lib/ronin/db/phone_number.rb
Overview
Represents a phone number.
Instance Attribute Summary collapse
-
#area_code ⇒ String?
The phone number area code (three digits after the country code).
-
#country_code ⇒ String?
The phone number country code (the first one or two digits).
-
#created_at ⇒ Time
Tracks when the phone number was first created.
-
#id ⇒ Integer
The primary key of the phone number.
-
#line_number ⇒ String
The phone number line number (last four digits).
-
#notes ⇒ Array<Note>
The associated notes.
-
#number ⇒ String
The phone number.
-
#organization_department ⇒ OrganizationDepartment?
The organization department that uses the email address.
-
#organization_members ⇒ OrganizationMember?
The organization member that use the phone number.
-
#organization_phone_number ⇒ OrganiationPhoneNumber?
The association of the organization that use the phone number.
-
#people ⇒ Array<Person>
The people that use this phone number.
-
#personal_phone_numbers ⇒ Array<PersonalPhoneNumber>
The association of people that use this phone number.
-
#prefix ⇒ String
The phone number prefix (three digits after the area code).
Class Method Summary collapse
-
.for_organization(name) ⇒ Array<PhoneNumber>
Queries all phone numbers associated with the organization name.
-
.for_person(full_name) ⇒ Array<PhoneNumber>
Queries all phone numbers associated with the person.
-
.import(number) ⇒ PhoneNumber
Imports an phone number.
-
.lookup(number) ⇒ PhoneNumber?
Looks up the phone number.
-
.parse(number) ⇒ Hash{Symbol => String,nil}
private
Parses the phone number.
-
.similar_to(number) ⇒ Array<PhoneNumber>
Finds all similar phone numbers with the matching phone number components.
-
.with_area_code(area_code) ⇒ Array<PhoneNumber>
Finds all phone numbers with the matching area code.
-
.with_country_code(country_code) ⇒ Array<PhoneNumber>
Finds all phone numbers with the matching country code.
-
.with_line_number(line_number) ⇒ Array<PhoneNumber>
Finds all phone numbers with the matching line number.
-
.with_prefix(prefix) ⇒ Array<PhoneNumber>
Finds all phone numbers with the matching prefix.
Instance Method Summary collapse
-
#to_s ⇒ String
Converts the phone number to a String.
Methods included from Model::Importable
Methods included from Model
Instance Attribute Details
#area_code ⇒ String?
The phone number area code (three digits after the country code).
71 |
# File 'lib/ronin/db/phone_number.rb', line 71 attribute :area_code, :string |
#country_code ⇒ String?
The phone number country code (the first one or two digits).
60 |
# File 'lib/ronin/db/phone_number.rb', line 60 attribute :country_code, :string |
#created_at ⇒ Time
Tracks when the phone number was first created.
104 |
# File 'lib/ronin/db/phone_number.rb', line 104 attribute :created_at, :datetime |
#id ⇒ Integer
The primary key of the phone number.
42 |
# File 'lib/ronin/db/phone_number.rb', line 42 attribute :id, :integer |
#line_number ⇒ String
The phone number line number (last four digits).
93 |
# File 'lib/ronin/db/phone_number.rb', line 93 attribute :line_number, :string |
#notes ⇒ Array<Note>
The associated notes.
140 |
# File 'lib/ronin/db/phone_number.rb', line 140 has_many :notes, dependent: :destroy |
#number ⇒ String
The phone number.
48 |
# File 'lib/ronin/db/phone_number.rb', line 48 attribute :number, :string |
#organization_department ⇒ OrganizationDepartment?
The organization department that uses the email address.
128 |
# File 'lib/ronin/db/phone_number.rb', line 128 has_one :organization_department, dependent: :nullify |
#organization_members ⇒ OrganizationMember?
The organization member that use the phone number.
134 |
# File 'lib/ronin/db/phone_number.rb', line 134 has_one :organization_member, dependent: :nullify |
#organization_phone_number ⇒ OrganiationPhoneNumber?
The association of the organization that use the phone number.
122 |
# File 'lib/ronin/db/phone_number.rb', line 122 has_one :organization_phone_number, dependent: :destroy |
#people ⇒ Array<Person>
The people that use this phone number.
116 |
# File 'lib/ronin/db/phone_number.rb', line 116 has_many :people, through: :personal_phone_numbers |
#personal_phone_numbers ⇒ Array<PersonalPhoneNumber>
The association of people that use this phone number.
110 |
# File 'lib/ronin/db/phone_number.rb', line 110 has_many :personal_phone_numbers, dependent: :destroy |
#prefix ⇒ String
The phone number prefix (three digits after the area code).
82 |
# File 'lib/ronin/db/phone_number.rb', line 82 attribute :prefix, :string |
Class Method Details
.for_organization(name) ⇒ Array<PhoneNumber>
Queries all phone numbers associated with the organization name.
224 225 226 227 228 229 230 |
# File 'lib/ronin/db/phone_number.rb', line 224 def self.for_organization(name) joins(organization_phone_number: :organization).where( organization_phone_number: { ronin_organizations: {name: name} } ) end |
.for_person(full_name) ⇒ Array<PhoneNumber>
Queries all phone numbers associated with the person.
209 210 211 |
# File 'lib/ronin/db/phone_number.rb', line 209 def self.for_person(full_name) joins(:people).where(people: {full_name: full_name}) end |
.import(number) ⇒ PhoneNumber
Imports an phone number.
194 195 196 |
# File 'lib/ronin/db/phone_number.rb', line 194 def self.import(number) create(parse(number)) end |
.lookup(number) ⇒ PhoneNumber?
Looks up the phone number.
153 154 155 |
# File 'lib/ronin/db/phone_number.rb', line 153 def self.lookup(number) find_by(number: number) end |
.parse(number) ⇒ Hash{Symbol => String,nil}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Parses the phone number.
168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/ronin/db/phone_number.rb', line 168 def self.parse(number) if (match = number.match(/\A(?:(?:\+?(?<country_code>\d{1,3})[\s.-])?(?:\((?<area_code>\d{3})\)|(?<area_code>\d{3}))[\s.-])?(?<prefix>\d{3})[\s.-](?<line_number>\d{4})\z/)) { number: number, country_code: match[:country_code], area_code: match[:area_code], prefix: match[:prefix], line_number: match[:line_number] } else raise(ArgumentError,"invalid phone number: #{number.inspect}") end end |
.similar_to(number) ⇒ Array<PhoneNumber>
Finds all similar phone numbers with the matching phone number components.
244 245 246 247 248 249 250 |
# File 'lib/ronin/db/phone_number.rb', line 244 def self.similar_to(number) attributes = parse(number) attributes.delete(:number) attributes.compact! where(**attributes) end |
.with_area_code(area_code) ⇒ Array<PhoneNumber>
Finds all phone numbers with the matching area code.
278 279 280 |
# File 'lib/ronin/db/phone_number.rb', line 278 def self.with_area_code(area_code) where(area_code: area_code) end |
.with_country_code(country_code) ⇒ Array<PhoneNumber>
Finds all phone numbers with the matching country code.
263 264 265 |
# File 'lib/ronin/db/phone_number.rb', line 263 def self.with_country_code(country_code) where(country_code: country_code) end |
.with_line_number(line_number) ⇒ Array<PhoneNumber>
Finds all phone numbers with the matching line number.
308 309 310 |
# File 'lib/ronin/db/phone_number.rb', line 308 def self.with_line_number(line_number) where(line_number: line_number) end |
.with_prefix(prefix) ⇒ Array<PhoneNumber>
Finds all phone numbers with the matching prefix.
293 294 295 |
# File 'lib/ronin/db/phone_number.rb', line 293 def self.with_prefix(prefix) where(prefix: prefix) end |
Instance Method Details
#to_s ⇒ String
Converts the phone number to a String.
317 318 319 |
# File 'lib/ronin/db/phone_number.rb', line 317 def to_s number end |