freight_kit 0.1.22 → 0.1.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 170c2e1d454e583098180d4ffa29c937dcc687972ebc896c58056bd3285e02f5
4
- data.tar.gz: c144297e62782b1f9836b4c24bc0367b2132d9319382c5b2e96668694b953247
3
+ metadata.gz: 378832bcfdc26a1c18c3eaa4f4a08b55dacff49e724b5d1e933de4cd9341e0d0
4
+ data.tar.gz: b14186797e2b67ece60437398fb1fee1c7664c7758138c1560acf3601fa9c5a8
5
5
  SHA512:
6
- metadata.gz: f2cadca4dbab2f033bf5b761131701a13807b7180ff5dd90f85ca79dc235bc109fa5afa7e908d9bfa19914ec5633b6ecec36653281e3bf0ae728e448b0fa9b1f
7
- data.tar.gz: 5c6cc78939f8d056a0e9dce8686ccffc1620619a582277074619a403943f335fda9a8935831d913a21e426e4fa488eb2f40ab7cecd0c1fe749a57b8b85995ed8
6
+ metadata.gz: 0e7542f3dc7aaf4362a47e713a9c6ee73322f1ecf1f95c512f2d304c0061bcac3d5c741b2469fb060274f3b0d3a4b8d36364ef092f46a45d9a74773d50fe8648
7
+ data.tar.gz: b13e4ece3fb6ffb4f68f0ec485607f986f7127437b37c53a19a8422b901eaa50ae1435573cc885588cb9e737d757db6f8d9d5c79aebbf5c17878483ce8b2cc2f
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.22
1
+ 0.1.23
Binary file
@@ -61,6 +61,10 @@ module FreightKit
61
61
  false
62
62
  end
63
63
 
64
+ # The directed lanes the carrier serves, for carriers that serve only some origins to some destinations.
65
+ # @return [Array<FreightKit::Lane>]
66
+ def lanes = []
67
+
64
68
  # The carrier's registered legal name, with its entity suffix (e.g. "Saia Motor Freight Line LLC"), when known.
65
69
  # {.name} is the name the carrier does business as.
66
70
  # @return [String, nil]
@@ -79,6 +83,16 @@ module FreightKit
79
83
  # @return [Hash{Symbol => Object}]
80
84
  def mappable_accessorials = {}
81
85
 
86
+ # The carrier's lanes that go from the origin to the destination, most specific first.
87
+ # @param destination [FreightKit::Location]
88
+ # @param origin [FreightKit::Location]
89
+ # @return [Array<FreightKit::Lane>]
90
+ def matching_lanes(origin, destination)
91
+ lanes
92
+ .select { |lane| lane.include?(origin, destination) }
93
+ .sort_by.with_index { |lane, index| [-lane.specificity, index] }
94
+ end
95
+
82
96
  # The maximum height the carrier will accept.
83
97
  # @return [Measured::Length]
84
98
  def maximum_height = Measured::Length.new(105, :inches)
@@ -143,6 +157,18 @@ module FreightKit
143
157
  # @return [String, nil]
144
158
  def scac = nil
145
159
 
160
+ # Whether the carrier serves a shipment from the origin to the destination: a lane matches, or both locations are
161
+ # inside its territories. A carrier without lanes or territories serves everywhere.
162
+ # @param destination [FreightKit::Location]
163
+ # @param origin [FreightKit::Location]
164
+ # @return [Boolean]
165
+ def serve?(origin, destination)
166
+ return true if lanes.blank? && territories.blank?
167
+
168
+ matching_lanes(origin, destination).any? ||
169
+ [origin, destination].all? { |location| territories.any? { |territory| territory.include?(location) } }
170
+ end
171
+
146
172
  # Raises {UnserviceableAccessorialsError} for accessorials the carrier refuses, or that it neither maps nor serves
147
173
  # unpriced. Returns false when the carrier maps no accessorials.
148
174
  # @return [Boolean]
@@ -167,6 +193,10 @@ module FreightKit
167
193
  # @return [Array<FreightKit::Terminal>]
168
194
  def terminals = []
169
195
 
196
+ # The areas the carrier picks up from and delivers to, in any combination.
197
+ # @return [Array<FreightKit::Territory>]
198
+ def territories = []
199
+
170
200
  # The template URL for tracking one of carrier's `NUMBERS` publicly. A template URL is a URL containing the token
171
201
  # "%s" that can be replaced to generate a valid URL.
172
202
  #
@@ -19,6 +19,17 @@ module FreightKit
19
19
  def id = 'e899224d-f3c9-47b5-9e2f-61c9c0d8c497'
20
20
  def name = 'A1 Express'
21
21
  def scac = 'AOXQ'
22
+
23
+ # Southern California, plus Las Vegas and all of Clark County, Nevada, by ZIP prefix.
24
+ def territories
25
+ country = Countries.find_by(iso31661_alpha2: 'US')
26
+ southern_california = [*'900'..'908', *'910'..'928', '930', '931', '935', '93225', '93243', '93420']
27
+
28
+ [
29
+ Territory.new(country:, postal_codes: southern_california, region_abbreviation: 'CA'),
30
+ Territory.new(country:, postal_codes: ['889', '890', '891'], region_abbreviation: 'NV')
31
+ ]
32
+ end
22
33
  end
23
34
  end
24
35
  end
@@ -16,6 +16,19 @@ module FreightKit
16
16
  end
17
17
 
18
18
  def id = '42b3f8f9-c85c-4144-b2e3-172386bc29d4'
19
+
20
+ def lanes
21
+ country = Countries.find_by(iso31661_alpha2: 'US')
22
+
23
+ [
24
+ Lane.new(
25
+ destination: Territory.new(country:, region_abbreviation: 'KS'),
26
+ id: '868188aa-d976-4c9a-8a06-0536bd0dc8f2',
27
+ origin: Territory.new(country:)
28
+ )
29
+ ]
30
+ end
31
+
19
32
  def name = 'GSP Express'
20
33
  def us_mc_number = 1_480_261
21
34
  end
@@ -18,6 +18,19 @@ module FreightKit
18
18
  end
19
19
 
20
20
  def id = '06cb58f8-4542-4ffc-aebc-98272678c78b'
21
+
22
+ def lanes
23
+ country = Countries.find_by(iso31661_alpha2: 'US')
24
+
25
+ [
26
+ Lane.new(
27
+ destination: Territory.new(country:, region_abbreviation: 'NY'),
28
+ id: '876f6e13-8611-4b8c-9982-8f661bc2684c',
29
+ origin: Territory.new(country:, region_abbreviation: 'WI')
30
+ )
31
+ ]
32
+ end
33
+
21
34
  def legal_name = 'Top-ten Express Corp'
22
35
  def name = 'Top Ten Express'
23
36
  def us_dot_number = 1_625_877
@@ -31,6 +31,27 @@ module FreightKit
31
31
  end
32
32
 
33
33
  def id = '2d9b9c4c-717e-4832-8c14-2c4e56b01ae7'
34
+
35
+ def lanes
36
+ country = Countries.find_by(iso31661_alpha2: 'US')
37
+ origin = Territory.new(country:, region_abbreviation: 'CA')
38
+
39
+ {
40
+ 'CO' => '9709c88e-5019-4bd7-81f4-25a4fc3d0357',
41
+ 'ID' => '2da75d3b-7e6c-4f00-b6b1-42b57f1bdbd6',
42
+ 'KS' => '9da3069e-ef97-4f96-a6bc-b7be662350ef',
43
+ 'MT' => '755ed10f-5dec-426c-8d22-f64dc1565ccd',
44
+ 'ND' => '087be435-b4cf-448d-b047-7afd54aa7565',
45
+ 'NE' => '6aed2331-66aa-4baa-8e4a-40d3bd2ec989',
46
+ 'NM' => '49a7987e-8ef8-43c3-b6fb-d122cc421648',
47
+ 'SD' => '75d5539f-f15b-495d-a551-1c79fb91bf39',
48
+ 'UT' => 'f6f9fccd-8ce1-43ca-a4a3-36c12d3f309c',
49
+ 'WY' => '3eb6baaa-cc92-4aa2-ae5f-40176f09e0a9'
50
+ }.map do |region_abbreviation, id|
51
+ Lane.new(destination: Territory.new(country:, region_abbreviation:), id:, origin:)
52
+ end
53
+ end
54
+
34
55
  def legal_name = 'South Coast Transportation & Dist. , Inc.'
35
56
  def name = 'Western Regional Delivery Service'
36
57
  def required_credential_types = %i[selenoid website]
@@ -0,0 +1,20 @@
1
+ module FreightKit
2
+ # Class representing a carrier's service in one direction, from one territory to another.
3
+ #
4
+ # @!attribute destination [FreightKit::Territory] Where the carrier delivers.
5
+ # @!attribute id [String] Permanent UUID. Applications store it, so never change it.
6
+ # @!attribute origin [FreightKit::Territory] Where the carrier picks up.
7
+ class Lane < Model
8
+ attr_accessor :destination, :id, :origin
9
+
10
+ # Whether the lane goes from the origin to the destination.
11
+ # @param destination [FreightKit::Location]
12
+ # @param origin [FreightKit::Location]
13
+ # @return [Boolean]
14
+ def include?(origin, destination) = self.origin.include?(origin) && self.destination.include?(destination)
15
+
16
+ # How narrow the lane is: the sum of its territories' specificity.
17
+ # @return [Integer]
18
+ def specificity = origin.specificity + destination.specificity
19
+ end
20
+ end
@@ -0,0 +1,37 @@
1
+ module FreightKit
2
+ # Class representing an area a carrier serves. A blank attribute matches any location.
3
+ #
4
+ # @!attribute country [FreightKit::Country] Country.
5
+ # @!attribute postal_codes [Array<String>] Postal codes or their prefixes (e.g. "850").
6
+ # @!attribute region_abbreviation [String, nil] Region (state or province) abbreviation, e.g. "CA".
7
+ class Territory < Model
8
+ attr_accessor :region_abbreviation
9
+ attr_reader :country
10
+
11
+ def country=(country)
12
+ raise ArgumentError, 'country must be a FreightKit::Country' unless country.is_a?(Country)
13
+
14
+ @country = country
15
+ end
16
+
17
+ # Whether the location is inside the territory.
18
+ # @param location [FreightKit::Location]
19
+ # @return [Boolean]
20
+ def include?(location)
21
+ return false unless location.country&.code(:alpha2)&.to_s == country.iso31661_alpha2
22
+ return false if region_abbreviation.present? && location.province != region_abbreviation
23
+
24
+ postal_codes.blank? || postal_codes.any? { |postal_code| location.postal_code.to_s.start_with?(postal_code) }
25
+ end
26
+
27
+ def postal_codes = @postal_codes || []
28
+
29
+ def postal_codes=(postal_codes)
30
+ @postal_codes = Array.wrap(postal_codes)
31
+ end
32
+
33
+ # How narrow the territory is: 0 for a country, 1 for a region, 2 for postal codes.
34
+ # @return [Integer]
35
+ def specificity = [region_abbreviation, postal_codes].count(&:present?)
36
+ end
37
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: freight_kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.22
4
+ version: 0.1.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Third Party Transportation Systems LLC
@@ -520,6 +520,7 @@ files:
520
520
  - accessorial_symbols.txt
521
521
  - configuration/locations/amazon_warehouses.yml
522
522
  - freight_kit-0.1.21.gem
523
+ - freight_kit-0.1.22.gem
523
524
  - freight_kit.gemspec
524
525
  - lib/freight_kit.rb
525
526
  - lib/freight_kit/address_normalizer.rb
@@ -879,6 +880,7 @@ files:
879
880
  - lib/freight_kit/models/date_time.rb
880
881
  - lib/freight_kit/models/document_response.rb
881
882
  - lib/freight_kit/models/label.rb
883
+ - lib/freight_kit/models/lane.rb
882
884
  - lib/freight_kit/models/location.rb
883
885
  - lib/freight_kit/models/pickup_response.rb
884
886
  - lib/freight_kit/models/price.rb
@@ -889,6 +891,7 @@ files:
889
891
  - lib/freight_kit/models/shipment.rb
890
892
  - lib/freight_kit/models/shipment_event.rb
891
893
  - lib/freight_kit/models/terminal.rb
894
+ - lib/freight_kit/models/territory.rb
892
895
  - lib/freight_kit/models/tracking_response.rb
893
896
  - lib/freight_kit/package.rb
894
897
  - lib/freight_kit/package_item.rb