class Physical::Location

Constants

ADDRESS_TYPES

Attributes

address1[R]
address2[R]
address3[R]
address_type[R]
city[R]
company_name[R]
country[R]
email[R]
fax[R]
latitude[R]
longitude[R]
name[R]
phone[R]
region[R]
zip[R]

Public Class Methods

new( 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 ) click to toggle source
# File lib/physical/location.rb, line 25
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
  )

  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
  @latitude = latitude
  @longitude = longitude
end

Public Instance Methods

==(other) click to toggle source
# File lib/physical/location.rb, line 100
def ==(other)
  other.is_a?(self.class) &&
    to_hash == other&.to_hash
end
commercial?() click to toggle source
# File lib/physical/location.rb, line 74
def commercial?
  @address_type == 'commercial'
end
po_box?() click to toggle source
# File lib/physical/location.rb, line 78
def po_box?
  @address_type == 'po_box'
end
residential?() click to toggle source
# File lib/physical/location.rb, line 70
def residential?
  @address_type == 'residential'
end
to_hash() click to toggle source
# File lib/physical/location.rb, line 82
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