Class: Physical::Location

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

Constant Summary collapse

ADDRESS_TYPES =
%w(residential commercial po_box)

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) ⇒ Location

Returns a new instance of Location.



23
24
25
26
27
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
# File 'lib/physical/location.rb', line 23

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
  )

  if country.is_a?(Carmen::Country)
    @country = country
  else
    @country = 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
end

Instance Attribute Details

#address1Object (readonly)

Returns the value of attribute address1.



9
10
11
# File 'lib/physical/location.rb', line 9

def address1
  @address1
end

#address2Object (readonly)

Returns the value of attribute address2.



9
10
11
# File 'lib/physical/location.rb', line 9

def address2
  @address2
end

#address3Object (readonly)

Returns the value of attribute address3.



9
10
11
# File 'lib/physical/location.rb', line 9

def address3
  @address3
end

#address_typeObject (readonly)

Returns the value of attribute address_type.



9
10
11
# File 'lib/physical/location.rb', line 9

def address_type
  @address_type
end

#cityObject (readonly)

Returns the value of attribute city.



9
10
11
# File 'lib/physical/location.rb', line 9

def city
  @city
end

#company_nameObject (readonly)

Returns the value of attribute company_name.



9
10
11
# File 'lib/physical/location.rb', line 9

def company_name
  @company_name
end

#countryObject (readonly)

Returns the value of attribute country.



9
10
11
# File 'lib/physical/location.rb', line 9

def country
  @country
end

#emailObject (readonly)

Returns the value of attribute email.



9
10
11
# File 'lib/physical/location.rb', line 9

def email
  @email
end

#faxObject (readonly)

Returns the value of attribute fax.



9
10
11
# File 'lib/physical/location.rb', line 9

def fax
  @fax
end

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/physical/location.rb', line 9

def name
  @name
end

#phoneObject (readonly)

Returns the value of attribute phone.



9
10
11
# File 'lib/physical/location.rb', line 9

def phone
  @phone
end

#regionObject (readonly)

Returns the value of attribute region.



9
10
11
# File 'lib/physical/location.rb', line 9

def region
  @region
end

#zipObject (readonly)

Returns the value of attribute zip.



9
10
11
# File 'lib/physical/location.rb', line 9

def zip
  @zip
end

Instance Method Details

#==(other) ⇒ Object



94
95
96
# File 'lib/physical/location.rb', line 94

def ==(other)
  to_hash == other.to_hash
end

#commercial?Boolean

Returns:

  • (Boolean)


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

def commercial?
  @address_type == 'commercial'
end

#po_box?Boolean

Returns:

  • (Boolean)


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

def po_box?
  @address_type == 'po_box'
end

#residential?Boolean

Returns:

  • (Boolean)


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

def residential?
  @address_type == 'residential'
end

#to_hashObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/physical/location.rb', line 76

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