Class: Physical::Location
- Inherits:
-
Object
- Object
- Physical::Location
- 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
-
#address1 ⇒ String
readonly
This location's address line 1.
-
#address2 ⇒ String
readonly
This location's address line 2.
-
#address3 ⇒ String
readonly
This location's address line 3.
-
#address_type ⇒ String
readonly
This location's address type (see ADDRESS_TYPES).
-
#city ⇒ String
readonly
This location's city.
-
#company_name ⇒ String
readonly
This location's company name.
-
#country ⇒ Carmen::Country
readonly
This location's country.
-
#email ⇒ String
readonly
This location's email.
-
#fax ⇒ String
readonly
This location's fax.
-
#latitude ⇒ String
readonly
This location's latitude.
-
#longitude ⇒ String
readonly
This location's longitude.
-
#name ⇒ String
readonly
This location's name (could be a person's name).
-
#phone ⇒ String
readonly
This location's phone.
-
#properties ⇒ String
readonly
Additional custom properties for this location.
-
#region ⇒ Carmen::Region
readonly
This location's state or province.
-
#zip ⇒ String
readonly
This location's postal code.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Returns true if the given object's class and #to_hash match this location.
-
#commercial? ⇒ Boolean
Returns true if this location's address type is "commercial".
-
#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
constructor
A new instance of Location.
-
#po_box? ⇒ Boolean
Returns true if this location's address type is "po_box".
-
#residential? ⇒ Boolean
Returns true if this location's address type is "residential".
-
#to_hash ⇒ Hash
Returns a hash representation of this location.
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.
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
#address1 ⇒ String (readonly)
This location's address line 1
35 36 37 |
# File 'lib/physical/location.rb', line 35 def address1 @address1 end |
#address2 ⇒ String (readonly)
This location's address line 2
39 40 41 |
# File 'lib/physical/location.rb', line 39 def address2 @address2 end |
#address3 ⇒ String (readonly)
This location's address line 3
43 44 45 |
# File 'lib/physical/location.rb', line 43 def address3 @address3 end |
#address_type ⇒ String (readonly)
This location's address type (see ADDRESS_TYPES)
59 60 61 |
# File 'lib/physical/location.rb', line 59 def address_type @address_type end |
#city ⇒ String (readonly)
This location's city
27 28 29 |
# File 'lib/physical/location.rb', line 27 def city @city end |
#company_name ⇒ String (readonly)
This location's company name
63 64 65 |
# File 'lib/physical/location.rb', line 63 def company_name @company_name end |
#country ⇒ Carmen::Country (readonly)
This location's country
15 16 17 |
# File 'lib/physical/location.rb', line 15 def country @country end |
#email ⇒ String (readonly)
This location's email
55 56 57 |
# File 'lib/physical/location.rb', line 55 def email @email end |
#fax ⇒ String (readonly)
This location's fax
51 52 53 |
# File 'lib/physical/location.rb', line 51 def fax @fax end |
#latitude ⇒ String (readonly)
This location's latitude
67 68 69 |
# File 'lib/physical/location.rb', line 67 def latitude @latitude end |
#longitude ⇒ String (readonly)
This location's longitude
71 72 73 |
# File 'lib/physical/location.rb', line 71 def longitude @longitude end |
#name ⇒ String (readonly)
This location's name (could be a person's name)
31 32 33 |
# File 'lib/physical/location.rb', line 31 def name @name end |
#phone ⇒ String (readonly)
This location's phone
47 48 49 |
# File 'lib/physical/location.rb', line 47 def phone @phone end |
#properties ⇒ String (readonly)
Additional custom properties for this location
75 76 77 |
# File 'lib/physical/location.rb', line 75 def properties @properties end |
#region ⇒ Carmen::Region (readonly)
This location's state or province
23 24 25 |
# File 'lib/physical/location.rb', line 23 def region @region end |
#zip ⇒ String (readonly)
This location's postal code
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.
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"
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"
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"
142 143 144 |
# File 'lib/physical/location.rb', line 142 def residential? @address_type == 'residential' end |
#to_hash ⇒ Hash
Returns a hash representation of this location.
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 |