Class: Ronin::DB::Person

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Model, Model::Importable
Defined in:
lib/ronin/db/person.rb

Overview

Represents a person.

Since:

  • 0.2.0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Model::Importable

included

Methods included from Model

included

Instance Attribute Details

#connected_peopleArray<Person>

The other people connected to the person.

Returns:



173
174
# File 'lib/ronin/db/person.rb', line 173

has_many :connected_people, through: :personal_connections,
source:  :other_person

#created_atTime

Tracks when the person was first created.

Returns:

  • (Time)


125
# File 'lib/ronin/db/person.rb', line 125

attribute :created_at, :datetime

#email_addressesArray<EmailAddress>

The email addresses associated with the person.

Returns:



161
# File 'lib/ronin/db/person.rb', line 161

has_many :email_addresses, through: :personal_email_addresses

#first_nameString

The person's first name.

Returns:

  • (String)


70
# File 'lib/ronin/db/person.rb', line 70

attribute :first_name, :string

#full_nameString

The person's full name.

Returns:

  • (String)


48
# File 'lib/ronin/db/person.rb', line 48

attribute :full_name, :string

#idInteger

The primary key of the person.

Returns:

  • (Integer)


42
# File 'lib/ronin/db/person.rb', line 42

attribute :id, :integer

#last_nameString?

The person's last name.

Returns:

  • (String, nil)


104
# File 'lib/ronin/db/person.rb', line 104

attribute :last_name, :string

#middle_initialString?

The person's middle initial.

Returns:

  • (String, nil)


92
# File 'lib/ronin/db/person.rb', line 92

attribute :middle_initial, :string

#middle_nameString?

The person's middle name.

Returns:

  • (String, nil)


81
# File 'lib/ronin/db/person.rb', line 81

attribute :middle_name, :string

#notesArray<Note>

The associated notes.

Returns:



194
# File 'lib/ronin/db/person.rb', line 194

has_many :notes, dependent: :destroy

#organization_customersArray<OrganizationCustomer>

The perons's customer relationships with other organizations.

Returns:



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_connectionsArray<PersonalConnection>

The perons's connections with other people.

Returns:



167
# File 'lib/ronin/db/person.rb', line 167

has_many :personal_connections, dependent: :destroy

#personal_email_addresssArray<PersonalEmailAddress>

The perons's email addresses.

Returns:



155
# File 'lib/ronin/db/person.rb', line 155

has_many :personal_email_addresses, dependent: :destroy

#personal_phone_numbersArray<PersonalPhoneNumber>

The perons's phone numbers.

Returns:



143
# File 'lib/ronin/db/person.rb', line 143

has_many :personal_phone_numbers, dependent: :destroy

#personal_street_addressesArray<PersonalStreetAddress>

The association of street addresses associated with the person.

Returns:



131
# File 'lib/ronin/db/person.rb', line 131

has_many :personal_street_addresses, dependent: :destroy

#phone_numbersArray<PhoneNumber>

The phone numbers associated with the person.

Returns:



149
# File 'lib/ronin/db/person.rb', line 149

has_many :phone_numbers, through: :personal_phone_numbers

#prefixString?

The person's prefix.

Returns:

  • (String, nil)


60
# File 'lib/ronin/db/person.rb', line 60

attribute :prefix, :string

#street_addressesArray<StreetAddress>

The street addresses associated with the person.

Returns:



137
# File 'lib/ronin/db/person.rb', line 137

has_many :street_addresses, through: :personal_street_addresses

#suffixString?

The person's suffix.

Returns:

  • (String, nil)


115
# File 'lib/ronin/db/person.rb', line 115

attribute :suffix, :string

#vendorsArray<Organization>

The vendor organizations of the person.

Returns:



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.

Parameters:

  • address (String)

    The street address to search for.

Returns:

  • (Array<Person>)

    The people associated with the street address.

Since:

  • 0.2.0



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.

Parameters:

  • city (String)

    The city to search for.

Returns:

  • (Array<Person>)

    The people associated with the city.

Since:

  • 0.2.0



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.

Parameters:

  • country (String)

    The country to search for.

Returns:

  • (Array<Person>)

    The people associated with the country.

Since:

  • 0.2.0



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.

Parameters:

  • province (String)

    The province to search for.

Returns:

  • (Array<Person>)

    The people associated with the province.

See Also:

Since:

  • 0.2.0



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.

Parameters:

  • state (String)

    The state to search for.

Returns:

  • (Array<Person>)

    The people associated with the state.

Since:

  • 0.2.0



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.

Parameters:

  • zipcode (String)

    The zipcode to search for.

Returns:

  • (Array<Person>)

    The people associated with the zipcode.

Since:

  • 0.2.0



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.

Parameters:

  • name (String)

    The person's full name.

Returns:

  • (Person)

    The imported person.

Since:

  • 0.2.0



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.

Parameters:

  • name (String)

    The person's full name to query.

Returns:

  • (Person, nil)

    The found person.

Since:

  • 0.2.0



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.

Parameters:

  • name (String)

    The person's full name to parse.

Returns:

  • (Hash{Symbol => String})

    The parsed attributes.

Since:

  • 0.2.0



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.

Parameters:

  • first_name (String)

    The first name to search for.

Returns:

Since:

  • 0.2.0



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.

Parameters:

  • last_name (String)

    The last name to search for.

Returns:

Since:

  • 0.2.0



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.

Parameters:

  • initial (String)

    The middle initial to search for.

Returns:

Since:

  • 0.2.0



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.

Parameters:

  • middle_name (String)

    The middle name to search for.

Returns:

Since:

  • 0.2.0



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.

Parameters:

  • prefix (String)

    The name prefix to search for.

Returns:

Since:

  • 0.2.0



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.

Parameters:

  • suffix (String)

    The name suffix to search for.

Returns:

Since:

  • 0.2.0



374
375
376
# File 'lib/ronin/db/person.rb', line 374

def self.with_suffix(suffix)
  where(suffix: suffix)
end

Instance Method Details

#to_sString

Converts the person into a String.

Returns:

  • (String)

    The person's full name.

Since:

  • 0.2.0



442
443
444
# File 'lib/ronin/db/person.rb', line 442

def to_s
  full_name
end