Class: Ronin::DB::Person
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Ronin::DB::Person
- Includes:
- Model, Model::Importable
- Defined in:
- lib/ronin/db/person.rb
Overview
Represents a person.
Instance Attribute Summary collapse
-
#connected_people ⇒ Array<Person>
The other people connected to the person.
-
#created_at ⇒ Time
Tracks when the person was first created.
-
#email_addresses ⇒ Array<EmailAddress>
The email addresses associated with the person.
-
#first_name ⇒ String
The person's first name.
-
#full_name ⇒ String
The person's full name.
-
#id ⇒ Integer
The primary key of the person.
-
#last_name ⇒ String?
The person's last name.
-
#middle_initial ⇒ String?
The person's middle initial.
-
#middle_name ⇒ String?
The person's middle name.
-
#notes ⇒ Array<Note>
The associated notes.
-
#organization_customers ⇒ Array<OrganizationCustomer>
The perons's customer relationships with other organizations.
-
#personal_connections ⇒ Array<PersonalConnection>
The perons's connections with other people.
-
#personal_email_addresss ⇒ Array<PersonalEmailAddress>
The perons's email addresses.
-
#personal_phone_numbers ⇒ Array<PersonalPhoneNumber>
The perons's phone numbers.
-
#personal_street_addresses ⇒ Array<PersonalStreetAddress>
The association of street addresses associated with the person.
-
#phone_numbers ⇒ Array<PhoneNumber>
The phone numbers associated with the person.
-
#prefix ⇒ String?
The person's prefix.
-
#street_addresses ⇒ Array<StreetAddress>
The street addresses associated with the person.
-
#suffix ⇒ String?
The person's suffix.
-
#vendors ⇒ Array<Organization>
The vendor organizations of the person.
Class Method Summary collapse
-
.for_address(address) ⇒ Array<Person>
Queries all people associated with the street address.
-
.for_city(city) ⇒ Array<Person>
Queries all people associated with the city.
-
.for_country(country) ⇒ Array<Person>
Queries all people associated with the country.
-
.for_province(province) ⇒ Array<Person>
Queries all people associated with the province.
-
.for_state(state) ⇒ Array<Person>
Queries all people associated with the state.
-
.for_zipcode(zipcode) ⇒ Array<Person>
Queries all people associated with the zipcode.
-
.import(name) ⇒ Person
Imports a person by name.
-
.lookup(name) ⇒ Person?
Looks up a person by name.
-
.parse(name) ⇒ Hash{Symbol => String}
private
Parses a person's full name into attributes.
-
.with_first_name(first_name) ⇒ Array<Person>
Queries all people with the matching first name.
-
.with_last_name(last_name) ⇒ Array<Person>
Queries all people with the matching last name.
-
.with_middle_initial(initial) ⇒ Array<Person>
Queries all people with the matching middle initial.
-
.with_middle_name(middle_name) ⇒ Array<Person>
Queries all people with the matching middle name.
-
.with_prefix(prefix) ⇒ Array<Person>
Queries all people with the given prefix.
-
.with_suffix(suffix) ⇒ Array<Person>
Queries all people with the given suffix.
Instance Method Summary collapse
-
#to_s ⇒ String
Converts the person into a String.
Methods included from Model::Importable
Methods included from Model
Instance Attribute Details
#connected_people ⇒ Array<Person>
The other people connected to the person.
173 174 |
# File 'lib/ronin/db/person.rb', line 173 has_many :connected_people, through: :personal_connections, source: :other_person |
#created_at ⇒ Time
Tracks when the person was first created.
125 |
# File 'lib/ronin/db/person.rb', line 125 attribute :created_at, :datetime |
#email_addresses ⇒ Array<EmailAddress>
The email addresses associated with the person.
161 |
# File 'lib/ronin/db/person.rb', line 161 has_many :email_addresses, through: :personal_email_addresses |
#first_name ⇒ String
The person's first name.
70 |
# File 'lib/ronin/db/person.rb', line 70 attribute :first_name, :string |
#full_name ⇒ String
The person's full name.
48 |
# File 'lib/ronin/db/person.rb', line 48 attribute :full_name, :string |
#id ⇒ Integer
The primary key of the person.
42 |
# File 'lib/ronin/db/person.rb', line 42 attribute :id, :integer |
#last_name ⇒ String?
The person's last name.
104 |
# File 'lib/ronin/db/person.rb', line 104 attribute :last_name, :string |
#middle_initial ⇒ String?
The person's middle initial.
92 |
# File 'lib/ronin/db/person.rb', line 92 attribute :middle_initial, :string |
#middle_name ⇒ String?
The person's middle name.
81 |
# File 'lib/ronin/db/person.rb', line 81 attribute :middle_name, :string |
#notes ⇒ Array<Note>
The associated notes.
194 |
# File 'lib/ronin/db/person.rb', line 194 has_many :notes, dependent: :destroy |
#organization_customers ⇒ Array<OrganizationCustomer>
The perons's customer relationships with other organizations.
180 181 182 |
# File 'lib/ronin/db/person.rb', line 180 has_many :organization_customers, class_name: 'OrganizationCustomer', foreign_key: :customer_id, dependent: :destroy |
#personal_connections ⇒ Array<PersonalConnection>
The perons's connections with other people.
167 |
# File 'lib/ronin/db/person.rb', line 167 has_many :personal_connections, dependent: :destroy |
#personal_email_addresss ⇒ Array<PersonalEmailAddress>
The perons's email addresses.
155 |
# File 'lib/ronin/db/person.rb', line 155 has_many :personal_email_addresses, dependent: :destroy |
#personal_phone_numbers ⇒ Array<PersonalPhoneNumber>
The perons's phone numbers.
143 |
# File 'lib/ronin/db/person.rb', line 143 has_many :personal_phone_numbers, dependent: :destroy |
#personal_street_addresses ⇒ Array<PersonalStreetAddress>
The association of street addresses associated with the person.
131 |
# File 'lib/ronin/db/person.rb', line 131 has_many :personal_street_addresses, dependent: :destroy |
#phone_numbers ⇒ Array<PhoneNumber>
The phone numbers associated with the person.
149 |
# File 'lib/ronin/db/person.rb', line 149 has_many :phone_numbers, through: :personal_phone_numbers |
#prefix ⇒ String?
The person's prefix.
60 |
# File 'lib/ronin/db/person.rb', line 60 attribute :prefix, :string |
#street_addresses ⇒ Array<StreetAddress>
The street addresses associated with the person.
137 |
# File 'lib/ronin/db/person.rb', line 137 has_many :street_addresses, through: :personal_street_addresses |
#suffix ⇒ String?
The person's suffix.
115 |
# File 'lib/ronin/db/person.rb', line 115 attribute :suffix, :string |
#vendors ⇒ Array<Organization>
The vendor organizations of the person.
188 |
# File 'lib/ronin/db/person.rb', line 188 has_many :vendors, through: :organization_customers |
Class Method Details
.for_address(address) ⇒ Array<Person>
Queries all people associated with the street address.
207 208 209 |
# File 'lib/ronin/db/person.rb', line 207 def self.for_address(address) joins(:street_addresses).where(street_addresses: {address: address}) end |
.for_city(city) ⇒ Array<Person>
Queries all people associated with the city.
222 223 224 |
# File 'lib/ronin/db/person.rb', line 222 def self.for_city(city) joins(:street_addresses).where(street_addresses: {city: city}) end |
.for_country(country) ⇒ Array<Person>
Queries all people associated with the country.
284 285 286 |
# File 'lib/ronin/db/person.rb', line 284 def self.for_country(country) joins(:street_addresses).where(street_addresses: {country: country}) end |
.for_province(province) ⇒ Array<Person>
Queries all people associated with the province.
254 255 256 |
# File 'lib/ronin/db/person.rb', line 254 def self.for_province(province) for_state(province) end |
.for_state(state) ⇒ Array<Person>
Queries all people associated with the state.
237 238 239 |
# File 'lib/ronin/db/person.rb', line 237 def self.for_state(state) joins(:street_addresses).where(street_addresses: {state: state}) end |
.for_zipcode(zipcode) ⇒ Array<Person>
Queries all people associated with the zipcode.
269 270 271 |
# File 'lib/ronin/db/person.rb', line 269 def self.for_zipcode(zipcode) joins(:street_addresses).where(street_addresses: {zipcode: zipcode}) end |
.import(name) ⇒ Person
Imports a person by name.
432 433 434 |
# File 'lib/ronin/db/person.rb', line 432 def self.import(name) create(parse(name)) end |
.lookup(name) ⇒ Person?
Looks up a person by name.
389 390 391 |
# File 'lib/ronin/db/person.rb', line 389 def self.lookup(name) find_by(full_name: name) end |
.parse(name) ⇒ Hash{Symbol => String}
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 a person's full name into attributes.
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 |
# File 'lib/ronin/db/person.rb', line 404 def self.parse(name) if (match = name.match(/\A(?:(?<prefix>Mr|Mrs|Ms|Miss|Dr|Sir|Madam|Master|Fr|Rev|Atty)\.?\s)?(?<first_name>\p{L}+(?:['-]\p{L}+)?)(?:(?:\s(?:(?:(?<middle_initial>\p{Lu})\.?)|(?<middle_name>(?<middle_initial>\p{Lu})\p{L}+(?:['-]\p{L}+)?)))?\s(?!Jr|Sr|II|III|IV|V|Esq|CPA|Dc|Dds|Vm|Jd|Md|Phd)(?<last_name>\p{L}+(?:['-]\p{L}+)?)(?:,?\s(?<suffix>Jr|Sr|II|III|IV|V|Esq|CPA|Dc|Dds|Vm|Jd|Md|Phd)\.?)?)?\z/)) { full_name: name, prefix: match[:prefix], first_name: match[:first_name], middle_name: match[:middle_name], middle_initial: match[:middle_initial], last_name: match[:last_name], suffix: match[:suffix] } else raise(ArgumentError,"invalid personal name: #{name.inspect}") end end |
.with_first_name(first_name) ⇒ Array<Person>
Queries all people with the matching first name.
314 315 316 |
# File 'lib/ronin/db/person.rb', line 314 def self.with_first_name(first_name) where(first_name: first_name) end |
.with_last_name(last_name) ⇒ Array<Person>
Queries all people with the matching last name.
359 360 361 |
# File 'lib/ronin/db/person.rb', line 359 def self.with_last_name(last_name) where(last_name: last_name) end |
.with_middle_initial(initial) ⇒ Array<Person>
Queries all people with the matching middle initial.
344 345 346 |
# File 'lib/ronin/db/person.rb', line 344 def self.with_middle_initial(initial) where(middle_initial: initial) end |
.with_middle_name(middle_name) ⇒ Array<Person>
Queries all people with the matching middle name.
329 330 331 |
# File 'lib/ronin/db/person.rb', line 329 def self.with_middle_name(middle_name) where(middle_name: middle_name) end |
.with_prefix(prefix) ⇒ Array<Person>
Queries all people with the given prefix.
299 300 301 |
# File 'lib/ronin/db/person.rb', line 299 def self.with_prefix(prefix) where(prefix: prefix) end |
.with_suffix(suffix) ⇒ Array<Person>
Queries all people with the given suffix.
374 375 376 |
# File 'lib/ronin/db/person.rb', line 374 def self.with_suffix(suffix) where(suffix: suffix) end |
Instance Method Details
#to_s ⇒ String
Converts the person into a String.
442 443 444 |
# File 'lib/ronin/db/person.rb', line 442 def to_s full_name end |