Class: FreightKit::Location

Inherits:
Model
  • Object
show all
Defined in:
lib/freight_kit/models/location.rb

Overview

Class representing a location.

Constant Summary collapse

TYPES =
%i[commercial po_box residential].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Model

#attributes, #initialize

Constructor Details

This class inherits a constructor from FreightKit::Model

Instance Attribute Details

#address1String?

The first street line

Returns:

  • (String, nil)


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/freight_kit/models/location.rb', line 53

class Location < Model
  TYPES = %i[commercial po_box residential].freeze

  attr_accessor :address1, :address2, :address3, :city, :postal_code, :province
  attr_reader :contact, :country, :lat, :lng, :type

  def contact=(contact)
    return @contact = nil if contact.blank?

    raise ArgumentError, 'contact must be a Contact' unless contact.is_a?(FreightKit::Contact)

    @contact = contact
  end

  def country=(country)
    return country = nil if country.blank?

    if country.is_a?(ActiveUtils::Country)
      @country = country
      return country
    end

    raise ArgumentError, 'country must be an ActiveUtils::Country'
  end

  def lat=(num)
    return @lat = nil if num.blank?

    return @lat = num if num.is_a?(BigNum)

    raise ArgumentError, 'lat must be a BigNum'
  end

  def lng=(num)
    return @lng = nil if num.blank?

    return @lng = num if num.is_a?(BigNum)

    raise ArgumentError, 'lng must be a BigNum'
  end

  def time_zone
    return if country&.code(:alpha2)&.blank? || province.blank? || city.blank?

    PlaceKit.lookup(country.code(:alpha2).to_s, province, city)
  end

  def type=(value)
    return @type = nil if value.blank?

    raise ArgumentError, "type must be one of :#{TYPES.join(", :")}" if TYPES.exclude?(value)

    @type = value
  end
end

#address2String?

The second street line

Returns:

  • (String, nil)


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/freight_kit/models/location.rb', line 53

class Location < Model
  TYPES = %i[commercial po_box residential].freeze

  attr_accessor :address1, :address2, :address3, :city, :postal_code, :province
  attr_reader :contact, :country, :lat, :lng, :type

  def contact=(contact)
    return @contact = nil if contact.blank?

    raise ArgumentError, 'contact must be a Contact' unless contact.is_a?(FreightKit::Contact)

    @contact = contact
  end

  def country=(country)
    return country = nil if country.blank?

    if country.is_a?(ActiveUtils::Country)
      @country = country
      return country
    end

    raise ArgumentError, 'country must be an ActiveUtils::Country'
  end

  def lat=(num)
    return @lat = nil if num.blank?

    return @lat = num if num.is_a?(BigNum)

    raise ArgumentError, 'lat must be a BigNum'
  end

  def lng=(num)
    return @lng = nil if num.blank?

    return @lng = num if num.is_a?(BigNum)

    raise ArgumentError, 'lng must be a BigNum'
  end

  def time_zone
    return if country&.code(:alpha2)&.blank? || province.blank? || city.blank?

    PlaceKit.lookup(country.code(:alpha2).to_s, province, city)
  end

  def type=(value)
    return @type = nil if value.blank?

    raise ArgumentError, "type must be one of :#{TYPES.join(", :")}" if TYPES.exclude?(value)

    @type = value
  end
end

#address3String?

The third street line

Returns:

  • (String, nil)


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/freight_kit/models/location.rb', line 53

class Location < Model
  TYPES = %i[commercial po_box residential].freeze

  attr_accessor :address1, :address2, :address3, :city, :postal_code, :province
  attr_reader :contact, :country, :lat, :lng, :type

  def contact=(contact)
    return @contact = nil if contact.blank?

    raise ArgumentError, 'contact must be a Contact' unless contact.is_a?(FreightKit::Contact)

    @contact = contact
  end

  def country=(country)
    return country = nil if country.blank?

    if country.is_a?(ActiveUtils::Country)
      @country = country
      return country
    end

    raise ArgumentError, 'country must be an ActiveUtils::Country'
  end

  def lat=(num)
    return @lat = nil if num.blank?

    return @lat = num if num.is_a?(BigNum)

    raise ArgumentError, 'lat must be a BigNum'
  end

  def lng=(num)
    return @lng = nil if num.blank?

    return @lng = num if num.is_a?(BigNum)

    raise ArgumentError, 'lng must be a BigNum'
  end

  def time_zone
    return if country&.code(:alpha2)&.blank? || province.blank? || city.blank?

    PlaceKit.lookup(country.code(:alpha2).to_s, province, city)
  end

  def type=(value)
    return @type = nil if value.blank?

    raise ArgumentError, "type must be one of :#{TYPES.join(", :")}" if TYPES.exclude?(value)

    @type = value
  end
end

#cityString?

The city name.

Returns:

  • (String, nil)


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/freight_kit/models/location.rb', line 53

class Location < Model
  TYPES = %i[commercial po_box residential].freeze

  attr_accessor :address1, :address2, :address3, :city, :postal_code, :province
  attr_reader :contact, :country, :lat, :lng, :type

  def contact=(contact)
    return @contact = nil if contact.blank?

    raise ArgumentError, 'contact must be a Contact' unless contact.is_a?(FreightKit::Contact)

    @contact = contact
  end

  def country=(country)
    return country = nil if country.blank?

    if country.is_a?(ActiveUtils::Country)
      @country = country
      return country
    end

    raise ArgumentError, 'country must be an ActiveUtils::Country'
  end

  def lat=(num)
    return @lat = nil if num.blank?

    return @lat = num if num.is_a?(BigNum)

    raise ArgumentError, 'lat must be a BigNum'
  end

  def lng=(num)
    return @lng = nil if num.blank?

    return @lng = num if num.is_a?(BigNum)

    raise ArgumentError, 'lng must be a BigNum'
  end

  def time_zone
    return if country&.code(:alpha2)&.blank? || province.blank? || city.blank?

    PlaceKit.lookup(country.code(:alpha2).to_s, province, city)
  end

  def type=(value)
    return @type = nil if value.blank?

    raise ArgumentError, "type must be one of :#{TYPES.join(", :")}" if TYPES.exclude?(value)

    @type = value
  end
end

#contactString?

The contact at the location.

Returns:

  • (String, nil)

Raises:

  • (ArgumentError)


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/freight_kit/models/location.rb', line 53

class Location < Model
  TYPES = %i[commercial po_box residential].freeze

  attr_accessor :address1, :address2, :address3, :city, :postal_code, :province
  attr_reader :contact, :country, :lat, :lng, :type

  def contact=(contact)
    return @contact = nil if contact.blank?

    raise ArgumentError, 'contact must be a Contact' unless contact.is_a?(FreightKit::Contact)

    @contact = contact
  end

  def country=(country)
    return country = nil if country.blank?

    if country.is_a?(ActiveUtils::Country)
      @country = country
      return country
    end

    raise ArgumentError, 'country must be an ActiveUtils::Country'
  end

  def lat=(num)
    return @lat = nil if num.blank?

    return @lat = num if num.is_a?(BigNum)

    raise ArgumentError, 'lat must be a BigNum'
  end

  def lng=(num)
    return @lng = nil if num.blank?

    return @lng = num if num.is_a?(BigNum)

    raise ArgumentError, 'lng must be a BigNum'
  end

  def time_zone
    return if country&.code(:alpha2)&.blank? || province.blank? || city.blank?

    PlaceKit.lookup(country.code(:alpha2).to_s, province, city)
  end

  def type=(value)
    return @type = nil if value.blank?

    raise ArgumentError, "type must be one of :#{TYPES.join(", :")}" if TYPES.exclude?(value)

    @type = value
  end
end

#countryActiveUtils::Country?

The country of the location.

Returns:

  • (ActiveUtils::Country, nil)

Raises:

  • (ArgumentError)


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/freight_kit/models/location.rb', line 53

class Location < Model
  TYPES = %i[commercial po_box residential].freeze

  attr_accessor :address1, :address2, :address3, :city, :postal_code, :province
  attr_reader :contact, :country, :lat, :lng, :type

  def contact=(contact)
    return @contact = nil if contact.blank?

    raise ArgumentError, 'contact must be a Contact' unless contact.is_a?(FreightKit::Contact)

    @contact = contact
  end

  def country=(country)
    return country = nil if country.blank?

    if country.is_a?(ActiveUtils::Country)
      @country = country
      return country
    end

    raise ArgumentError, 'country must be an ActiveUtils::Country'
  end

  def lat=(num)
    return @lat = nil if num.blank?

    return @lat = num if num.is_a?(BigNum)

    raise ArgumentError, 'lat must be a BigNum'
  end

  def lng=(num)
    return @lng = nil if num.blank?

    return @lng = num if num.is_a?(BigNum)

    raise ArgumentError, 'lng must be a BigNum'
  end

  def time_zone
    return if country&.code(:alpha2)&.blank? || province.blank? || city.blank?

    PlaceKit.lookup(country.code(:alpha2).to_s, province, city)
  end

  def type=(value)
    return @type = nil if value.blank?

    raise ArgumentError, "type must be one of :#{TYPES.join(", :")}" if TYPES.exclude?(value)

    @type = value
  end
end

#latBigNum?

The latitude of the location.

Returns:

  • (BigNum, nil)

Raises:

  • (ArgumentError)


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/freight_kit/models/location.rb', line 53

class Location < Model
  TYPES = %i[commercial po_box residential].freeze

  attr_accessor :address1, :address2, :address3, :city, :postal_code, :province
  attr_reader :contact, :country, :lat, :lng, :type

  def contact=(contact)
    return @contact = nil if contact.blank?

    raise ArgumentError, 'contact must be a Contact' unless contact.is_a?(FreightKit::Contact)

    @contact = contact
  end

  def country=(country)
    return country = nil if country.blank?

    if country.is_a?(ActiveUtils::Country)
      @country = country
      return country
    end

    raise ArgumentError, 'country must be an ActiveUtils::Country'
  end

  def lat=(num)
    return @lat = nil if num.blank?

    return @lat = num if num.is_a?(BigNum)

    raise ArgumentError, 'lat must be a BigNum'
  end

  def lng=(num)
    return @lng = nil if num.blank?

    return @lng = num if num.is_a?(BigNum)

    raise ArgumentError, 'lng must be a BigNum'
  end

  def time_zone
    return if country&.code(:alpha2)&.blank? || province.blank? || city.blank?

    PlaceKit.lookup(country.code(:alpha2).to_s, province, city)
  end

  def type=(value)
    return @type = nil if value.blank?

    raise ArgumentError, "type must be one of :#{TYPES.join(", :")}" if TYPES.exclude?(value)

    @type = value
  end
end

#lngBigNum?

The longitude of the location.

Returns:

  • (BigNum, nil)

Raises:

  • (ArgumentError)


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/freight_kit/models/location.rb', line 53

class Location < Model
  TYPES = %i[commercial po_box residential].freeze

  attr_accessor :address1, :address2, :address3, :city, :postal_code, :province
  attr_reader :contact, :country, :lat, :lng, :type

  def contact=(contact)
    return @contact = nil if contact.blank?

    raise ArgumentError, 'contact must be a Contact' unless contact.is_a?(FreightKit::Contact)

    @contact = contact
  end

  def country=(country)
    return country = nil if country.blank?

    if country.is_a?(ActiveUtils::Country)
      @country = country
      return country
    end

    raise ArgumentError, 'country must be an ActiveUtils::Country'
  end

  def lat=(num)
    return @lat = nil if num.blank?

    return @lat = num if num.is_a?(BigNum)

    raise ArgumentError, 'lat must be a BigNum'
  end

  def lng=(num)
    return @lng = nil if num.blank?

    return @lng = num if num.is_a?(BigNum)

    raise ArgumentError, 'lng must be a BigNum'
  end

  def time_zone
    return if country&.code(:alpha2)&.blank? || province.blank? || city.blank?

    PlaceKit.lookup(country.code(:alpha2).to_s, province, city)
  end

  def type=(value)
    return @type = nil if value.blank?

    raise ArgumentError, "type must be one of :#{TYPES.join(", :")}" if TYPES.exclude?(value)

    @type = value
  end
end

#postal_codeString?

The postal code (or ZIP® code) of the location.

Returns:

  • (String, nil)


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/freight_kit/models/location.rb', line 53

class Location < Model
  TYPES = %i[commercial po_box residential].freeze

  attr_accessor :address1, :address2, :address3, :city, :postal_code, :province
  attr_reader :contact, :country, :lat, :lng, :type

  def contact=(contact)
    return @contact = nil if contact.blank?

    raise ArgumentError, 'contact must be a Contact' unless contact.is_a?(FreightKit::Contact)

    @contact = contact
  end

  def country=(country)
    return country = nil if country.blank?

    if country.is_a?(ActiveUtils::Country)
      @country = country
      return country
    end

    raise ArgumentError, 'country must be an ActiveUtils::Country'
  end

  def lat=(num)
    return @lat = nil if num.blank?

    return @lat = num if num.is_a?(BigNum)

    raise ArgumentError, 'lat must be a BigNum'
  end

  def lng=(num)
    return @lng = nil if num.blank?

    return @lng = num if num.is_a?(BigNum)

    raise ArgumentError, 'lng must be a BigNum'
  end

  def time_zone
    return if country&.code(:alpha2)&.blank? || province.blank? || city.blank?

    PlaceKit.lookup(country.code(:alpha2).to_s, province, city)
  end

  def type=(value)
    return @type = nil if value.blank?

    raise ArgumentError, "type must be one of :#{TYPES.join(", :")}" if TYPES.exclude?(value)

    @type = value
  end
end

#provinceString?

The province (or state/territory) abbreviation of the location.

Returns:

  • (String, nil)


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/freight_kit/models/location.rb', line 53

class Location < Model
  TYPES = %i[commercial po_box residential].freeze

  attr_accessor :address1, :address2, :address3, :city, :postal_code, :province
  attr_reader :contact, :country, :lat, :lng, :type

  def contact=(contact)
    return @contact = nil if contact.blank?

    raise ArgumentError, 'contact must be a Contact' unless contact.is_a?(FreightKit::Contact)

    @contact = contact
  end

  def country=(country)
    return country = nil if country.blank?

    if country.is_a?(ActiveUtils::Country)
      @country = country
      return country
    end

    raise ArgumentError, 'country must be an ActiveUtils::Country'
  end

  def lat=(num)
    return @lat = nil if num.blank?

    return @lat = num if num.is_a?(BigNum)

    raise ArgumentError, 'lat must be a BigNum'
  end

  def lng=(num)
    return @lng = nil if num.blank?

    return @lng = num if num.is_a?(BigNum)

    raise ArgumentError, 'lng must be a BigNum'
  end

  def time_zone
    return if country&.code(:alpha2)&.blank? || province.blank? || city.blank?

    PlaceKit.lookup(country.code(:alpha2).to_s, province, city)
  end

  def type=(value)
    return @type = nil if value.blank?

    raise ArgumentError, "type must be one of :#{TYPES.join(", :")}" if TYPES.exclude?(value)

    @type = value
  end
end

#typeSymbol?

The type of the location.

It should be one of: :commercial, :po_box, :residential

Returns:

  • (Symbol, nil)

Raises:

  • (ArgumentError)


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/freight_kit/models/location.rb', line 53

class Location < Model
  TYPES = %i[commercial po_box residential].freeze

  attr_accessor :address1, :address2, :address3, :city, :postal_code, :province
  attr_reader :contact, :country, :lat, :lng, :type

  def contact=(contact)
    return @contact = nil if contact.blank?

    raise ArgumentError, 'contact must be a Contact' unless contact.is_a?(FreightKit::Contact)

    @contact = contact
  end

  def country=(country)
    return country = nil if country.blank?

    if country.is_a?(ActiveUtils::Country)
      @country = country
      return country
    end

    raise ArgumentError, 'country must be an ActiveUtils::Country'
  end

  def lat=(num)
    return @lat = nil if num.blank?

    return @lat = num if num.is_a?(BigNum)

    raise ArgumentError, 'lat must be a BigNum'
  end

  def lng=(num)
    return @lng = nil if num.blank?

    return @lng = num if num.is_a?(BigNum)

    raise ArgumentError, 'lng must be a BigNum'
  end

  def time_zone
    return if country&.code(:alpha2)&.blank? || province.blank? || city.blank?

    PlaceKit.lookup(country.code(:alpha2).to_s, province, city)
  end

  def type=(value)
    return @type = nil if value.blank?

    raise ArgumentError, "type must be one of :#{TYPES.join(", :")}" if TYPES.exclude?(value)

    @type = value
  end
end

Instance Method Details

#time_zoneObject



94
95
96
97
98
# File 'lib/freight_kit/models/location.rb', line 94

def time_zone
  return if country&.code(:alpha2)&.blank? || province.blank? || city.blank?

  PlaceKit.lookup(country.code(:alpha2).to_s, province, city)
end