Class: Physical::Location

Inherits:
Object
  • Object
show all
Includes:
PropertyReaders
Defined in:
lib/physical/location.rb

Overview

Represents a physical location.

Constant Summary collapse

ADDRESS_TYPES =

Possible address types for this location

%w(residential commercial po_box).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name: nil, company_name: nil, address1: nil, address2: nil, address3: nil, city: nil, region: nil, zip: nil, country: nil, phone: nil, fax: nil, email: nil, address_type: nil, latitude: nil, longitude: nil, properties: {}) ⇒ Location

Returns a new instance of Location.

Parameters:

  • name (String) (defaults to: nil)

    the name of this location (could be a person's name)

  • company_name (String) (defaults to: nil)

    the name of the company at this location

  • address1 (String) (defaults to: nil)

    the first line of the address

  • address2 (String) (defaults to: nil)

    the second line of the address

  • address3 (String) (defaults to: nil)

    the third line of the address

  • city (String) (defaults to: nil)

    the city

  • region (String, Carmen::Region) (defaults to: nil)

    the state or province

  • zip (String) (defaults to: nil)

    the postal code

  • country (String, Carmen::Country) (defaults to: nil)

    the country

  • phone (String) (defaults to: nil)

    the phone number

  • fax (String) (defaults to: nil)

    the fax number

  • email (String) (defaults to: nil)

    the email address

  • address_type (String) (defaults to: nil)

    the type of address (see ADDRESS_TYPES)

  • latitude (String) (defaults to: nil)

    the latitude at this location

  • longitude (String) (defaults to: nil)

    the longitude at this location

  • properties (Hash) (defaults to: {})

    additional custom properties for this location



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/physical/location.rb', line 93

def initialize(
  name: nil,
  company_name: nil,
  address1: nil,
  address2: nil,
  address3: nil,
  city: nil,
  region: nil,
  zip: nil,
  country: nil,
  phone: nil,
  fax: nil,
  email: nil,
  address_type: nil,
  latitude: nil,
  longitude: nil,
  properties: {}
)

  @country = if country.is_a?(Carmen::Country)
               country
             else
               Carmen::Country.coded(country.to_s)
             end

  if region.is_a?(Carmen::Region)
    @region = region
  elsif @country.is_a?(Carmen::Country)
    @region = @country.subregions.coded(region.to_s.upcase)
  end

  @name = name
  @company_name = company_name
  @address1 = address1
  @address2 = address2
  @address3 = address3
  @city = city
  @zip = zip
  @phone = phone
  @fax = fax
  @email = email
  @address_type = address_type
  @latitude = latitude
  @longitude = longitude
  @properties = properties
end

Instance Attribute Details

#address1String (readonly)

This location's address line 1

Returns:

  • (String)


35
36
37
# File 'lib/physical/location.rb', line 35

def address1
  @address1
end

#address2String (readonly)

This location's address line 2

Returns:

  • (String)


39
40
41
# File 'lib/physical/location.rb', line 39

def address2
  @address2
end

#address3String (readonly)

This location's address line 3

Returns:

  • (String)


43
44
45
# File 'lib/physical/location.rb', line 43

def address3
  @address3
end

#address_typeString (readonly)

This location's address type (see ADDRESS_TYPES)

Returns:

  • (String)


59
60
61
# File 'lib/physical/location.rb', line 59

def address_type
  @address_type
end

#cityString (readonly)

This location's city

Returns:

  • (String)


27
28
29
# File 'lib/physical/location.rb', line 27

def city
  @city
end

#company_nameString (readonly)

This location's company name

Returns:

  • (String)


63
64
65
# File 'lib/physical/location.rb', line 63

def company_name
  @company_name
end

#countryCarmen::Country (readonly)

This location's country

Returns:

  • (Carmen::Country)


15
16
17
# File 'lib/physical/location.rb', line 15

def country
  @country
end

#emailString (readonly)

This location's email

Returns:

  • (String)


55
56
57
# File 'lib/physical/location.rb', line 55

def email
  @email
end

#faxString (readonly)

This location's fax

Returns:

  • (String)


51
52
53
# File 'lib/physical/location.rb', line 51

def fax
  @fax
end

#latitudeString (readonly)

This location's latitude

Returns:

  • (String)


67
68
69
# File 'lib/physical/location.rb', line 67

def latitude
  @latitude
end

#longitudeString (readonly)

This location's longitude

Returns:

  • (String)


71
72
73
# File 'lib/physical/location.rb', line 71

def longitude
  @longitude
end

#nameString (readonly)

This location's name (could be a person's name)

Returns:

  • (String)


31
32
33
# File 'lib/physical/location.rb', line 31

def name
  @name
end

#phoneString (readonly)

This location's phone

Returns:

  • (String)


47
48
49
# File 'lib/physical/location.rb', line 47

def phone
  @phone
end

#propertiesString (readonly)

Additional custom properties for this location

Returns:

  • (String)


75
76
77
# File 'lib/physical/location.rb', line 75

def properties
  @properties
end

#regionCarmen::Region (readonly)

This location's state or province

Returns:

  • (Carmen::Region)


23
24
25
# File 'lib/physical/location.rb', line 23

def region
  @region
end

#zipString (readonly)

This location's postal code

Returns:

  • (String)


19
20
21
# File 'lib/physical/location.rb', line 19

def zip
  @zip
end

Instance Method Details

#==(other) ⇒ Boolean

Returns true if the given object's class and #to_hash match this location.

Returns:

  • (Boolean)


180
181
182
183
# File 'lib/physical/location.rb', line 180

def ==(other)
  other.is_a?(self.class) &&
    to_hash == other&.to_hash
end

#commercial?Boolean

Returns true if this location's address type is "commercial"

Returns:

  • (Boolean)


148
149
150
# File 'lib/physical/location.rb', line 148

def commercial?
  @address_type == 'commercial'
end

#po_box?Boolean

Returns true if this location's address type is "po_box"

Returns:

  • (Boolean)


154
155
156
# File 'lib/physical/location.rb', line 154

def po_box?
  @address_type == 'po_box'
end

#residential?Boolean

Returns true if this location's address type is "residential"

Returns:

  • (Boolean)


142
143
144
# File 'lib/physical/location.rb', line 142

def residential?
  @address_type == 'residential'
end

#to_hashHash

Returns a hash representation of this location.

Returns:

  • (Hash)


160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/physical/location.rb', line 160

def to_hash
  {
    country: country&.code,
    postal_code: zip,
    region: region&.code,
    city: city,
    name: name,
    address1: address1,
    address2: address2,
    address3: address3,
    phone: phone,
    fax: fax,
    email: email,
    address_type: address_type,
    company_name: company_name
  }
end