Class: Physical::Location
- Inherits:
-
Object
- Object
- Physical::Location
- Includes:
- PropertyReaders
- Defined in:
- lib/physical/location.rb
Constant Summary collapse
- ADDRESS_TYPES =
%w(residential commercial po_box).freeze
Instance Attribute Summary collapse
-
#address1 ⇒ Object
readonly
Returns the value of attribute address1.
-
#address2 ⇒ Object
readonly
Returns the value of attribute address2.
-
#address3 ⇒ Object
readonly
Returns the value of attribute address3.
-
#address_type ⇒ Object
readonly
Returns the value of attribute address_type.
-
#city ⇒ Object
readonly
Returns the value of attribute city.
-
#company_name ⇒ Object
readonly
Returns the value of attribute company_name.
-
#country ⇒ Object
readonly
Returns the value of attribute country.
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#fax ⇒ Object
readonly
Returns the value of attribute fax.
-
#latitude ⇒ Object
readonly
Returns the value of attribute latitude.
-
#longitude ⇒ Object
readonly
Returns the value of attribute longitude.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#phone ⇒ Object
readonly
Returns the value of attribute phone.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
-
#region ⇒ Object
readonly
Returns the value of attribute region.
-
#zip ⇒ Object
readonly
Returns the value of attribute zip.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #commercial? ⇒ Boolean
-
#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
- #residential? ⇒ Boolean
- #to_hash ⇒ Object
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.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/physical/location.rb', line 28 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 |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Physical::PropertyReaders
Instance Attribute Details
#address1 ⇒ Object (readonly)
Returns the value of attribute address1.
11 12 13 |
# File 'lib/physical/location.rb', line 11 def address1 @address1 end |
#address2 ⇒ Object (readonly)
Returns the value of attribute address2.
11 12 13 |
# File 'lib/physical/location.rb', line 11 def address2 @address2 end |
#address3 ⇒ Object (readonly)
Returns the value of attribute address3.
11 12 13 |
# File 'lib/physical/location.rb', line 11 def address3 @address3 end |
#address_type ⇒ Object (readonly)
Returns the value of attribute address_type.
11 12 13 |
# File 'lib/physical/location.rb', line 11 def address_type @address_type end |
#city ⇒ Object (readonly)
Returns the value of attribute city.
11 12 13 |
# File 'lib/physical/location.rb', line 11 def city @city end |
#company_name ⇒ Object (readonly)
Returns the value of attribute company_name.
11 12 13 |
# File 'lib/physical/location.rb', line 11 def company_name @company_name end |
#country ⇒ Object (readonly)
Returns the value of attribute country.
11 12 13 |
# File 'lib/physical/location.rb', line 11 def country @country end |
#email ⇒ Object (readonly)
Returns the value of attribute email.
11 12 13 |
# File 'lib/physical/location.rb', line 11 def email @email end |
#fax ⇒ Object (readonly)
Returns the value of attribute fax.
11 12 13 |
# File 'lib/physical/location.rb', line 11 def fax @fax end |
#latitude ⇒ Object (readonly)
Returns the value of attribute latitude.
11 12 13 |
# File 'lib/physical/location.rb', line 11 def latitude @latitude end |
#longitude ⇒ Object (readonly)
Returns the value of attribute longitude.
11 12 13 |
# File 'lib/physical/location.rb', line 11 def longitude @longitude end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/physical/location.rb', line 11 def name @name end |
#phone ⇒ Object (readonly)
Returns the value of attribute phone.
11 12 13 |
# File 'lib/physical/location.rb', line 11 def phone @phone end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
11 12 13 |
# File 'lib/physical/location.rb', line 11 def properties @properties end |
#region ⇒ Object (readonly)
Returns the value of attribute region.
11 12 13 |
# File 'lib/physical/location.rb', line 11 def region @region end |
#zip ⇒ Object (readonly)
Returns the value of attribute zip.
11 12 13 |
# File 'lib/physical/location.rb', line 11 def zip @zip end |
Instance Method Details
#==(other) ⇒ Object
105 106 107 108 |
# File 'lib/physical/location.rb', line 105 def ==(other) other.is_a?(self.class) && to_hash == other&.to_hash end |
#commercial? ⇒ Boolean
79 80 81 |
# File 'lib/physical/location.rb', line 79 def commercial? @address_type == 'commercial' end |
#po_box? ⇒ Boolean
83 84 85 |
# File 'lib/physical/location.rb', line 83 def po_box? @address_type == 'po_box' end |
#residential? ⇒ Boolean
75 76 77 |
# File 'lib/physical/location.rb', line 75 def residential? @address_type == 'residential' end |
#to_hash ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/physical/location.rb', line 87 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 |