Class: Ronin::DB::StreetAddress

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

Overview

Represents a street address.

Since:

  • 0.2.0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Model

included

Instance Attribute Details

#addressString

The address number and street name.

Returns:

  • (String)


46
# File 'lib/ronin/db/street_address.rb', line 46

attribute :address, :string

#cityString

The city name.

Returns:

  • (String)


62
# File 'lib/ronin/db/street_address.rb', line 62

attribute :city, :string

#countryString

The country name.

Returns:

  • (String)


96
# File 'lib/ronin/db/street_address.rb', line 96

attribute :country, :string

#created_atTime

Tracks when the street address was first created.

Returns:

  • (Time)


108
# File 'lib/ronin/db/street_address.rb', line 108

attribute :created_at, :datetime

#idInteger

The primary key of the street address.

Returns:

  • (Integer)


40
# File 'lib/ronin/db/street_address.rb', line 40

attribute :id, :integer

#notesArray<Note>

The associated notes.

Returns:



126
# File 'lib/ronin/db/street_address.rb', line 126

has_many :notes

#organization_departmentsArray<OrganizationDepartment>

The organization departments located at the street address.

Returns:



139
# File 'lib/ronin/db/street_address.rb', line 139

has_many :organization_departments, dependent: :nullify

#organization_street_addressesArray<OrganizationStreetAddress>

The association of organizations that associate with the street address.

Returns:



133
# File 'lib/ronin/db/street_address.rb', line 133

has_many :organization_street_addresses, dependent: :destroy

#peopleArray<Organization>

The people that are associated with the street addresses.

Returns:



120
# File 'lib/ronin/db/street_address.rb', line 120

has_many :people, through: :personal_street_addresses

#personal_street_addressesArray<PersonalStreetAddress>

The association of people that associate with the street address.

Returns:



114
# File 'lib/ronin/db/street_address.rb', line 114

has_many :personal_street_addresses, dependent: :destroy

#stateString?

The state or province name.

Returns:

  • (String, nil)


74
# File 'lib/ronin/db/street_address.rb', line 74

attribute :state, :string

#zipcodeString?

The zipcode or postal code.

Returns:

  • (String, nil)


85
# File 'lib/ronin/db/street_address.rb', line 85

attribute :zipcode, :string

Class Method Details

.for_organization(name) ⇒ Array<StreetAddress>

Queries all street addresses associated with an organization's name.

Parameters:

  • name (String)

    The organization name to search for.

Returns:

  • (Array<StreetAddress>)

    The street addresses associated with the organization.

Since:

  • 0.2.0



167
168
169
170
171
172
173
# File 'lib/ronin/db/street_address.rb', line 167

def self.for_organization(name)
  joins(organization_street_addresses: :organization).where(
    organization_street_addresses: {
      ronin_organizations: {name: name}
    }
  )
end

.for_person(full_name) ⇒ Array<StreetAddress>

Queries all street addresses associated with the person's full name.

Parameters:

  • full_name (String)

    The person's full name to search for.

Returns:

  • (Array<StreetAddress>)

    The street addresses associated with the person.

Since:

  • 0.2.0



152
153
154
# File 'lib/ronin/db/street_address.rb', line 152

def self.for_person(full_name)
  joins(:people).where(people: {full_name: full_name})
end

.with_address(address) ⇒ Array<StreetAddress>

Queries all street addresses with the matching address.

Parameters:

  • address (String)

    The street address to search for.

Returns:

Since:

  • 0.2.0



186
187
188
# File 'lib/ronin/db/street_address.rb', line 186

def self.with_address(address)
  where(address: address)
end

.with_city(city) ⇒ Array<StreetAddress>

Queries all street addresses with the matching city.

Parameters:

  • city (String)

    The city to search for.

Returns:

Since:

  • 0.2.0



201
202
203
# File 'lib/ronin/db/street_address.rb', line 201

def self.with_city(city)
  where(city: city)
end

.with_country(country) ⇒ Array<StreetAddress>

Queries all street addresses with the matching country.

Parameters:

  • country (String)

    The country to search for.

Returns:

Since:

  • 0.2.0



242
243
244
# File 'lib/ronin/db/street_address.rb', line 242

def self.with_country(country)
  where(country: country)
end

.with_province(province) ⇒ Object

Alias for with_state.

See Also:

Since:

  • 0.2.0



227
228
229
# File 'lib/ronin/db/street_address.rb', line 227

def self.with_province(province)
  with_state(province)
end

.with_state(state) ⇒ Array<StreetAddress>

Queries all street addresses with the matching state.

Parameters:

  • state (String)

    The state to search for.

Returns:

Since:

  • 0.2.0



216
217
218
# File 'lib/ronin/db/street_address.rb', line 216

def self.with_state(state)
  where(state: state)
end

.with_zipcode(zipcode) ⇒ Array<StreetAddress>

Queries all street addresses with the matching zipcode.

Parameters:

  • zipcode (String)

    The zipcode to search for.

Returns:

Since:

  • 0.2.0



257
258
259
# File 'lib/ronin/db/street_address.rb', line 257

def self.with_zipcode(zipcode)
  where(zipcode: zipcode)
end

Instance Method Details

#postal_codeString?

Alias for #zipcode.

Returns:

  • (String, nil)

See Also:

Since:

  • 0.2.0



299
300
301
# File 'lib/ronin/db/street_address.rb', line 299

def postal_code
  zipcode
end

#postal_code=(new_postal_code) ⇒ String?

Alias for #zipcode=.

Parameters:

  • new_postal_code (String, nil)

    The new postal code value.

Returns:

  • (String, nil)

See Also:

Since:

  • 0.2.0



315
316
317
# File 'lib/ronin/db/street_address.rb', line 315

def postal_code=(new_postal_code)
  self.zipcode = new_postal_code
end

#provinceString?

Alias for #state.

Returns:

  • (String, nil)

See Also:

Since:

  • 0.2.0



270
271
272
# File 'lib/ronin/db/street_address.rb', line 270

def province
  state
end

#province=(new_province) ⇒ String?

Alias for #state=.

Parameters:

  • new_province (String, nil)

    The new province value.

Returns:

  • (String, nil)

See Also:

Since:

  • 0.2.0



286
287
288
# File 'lib/ronin/db/street_address.rb', line 286

def province=(new_province)
  self.state = new_province
end

#to_sString

Converts the street address to a String.

Returns:

  • (String)

Since:

  • 0.2.0



324
325
326
327
328
329
330
# File 'lib/ronin/db/street_address.rb', line 324

def to_s
  string = "#{address}#{$/}#{city}"
  string << ", #{state}"  if state
  string << " #{zipcode}" if zipcode
  string << "#{$/}#{country}"
  return string
end