physical 0.4.9 → 0.5.0

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: 8198a4417d9f1dd923a4bfee9bf8695ecb1c270853182a92835e64c1b9f4e10c
4
- data.tar.gz: 8a007792624c95421bce9a09abb978de1142b8a2bfbfe6cef049c860ca101416
3
+ metadata.gz: 03d9eb10ac73675e3aa2bac745e7a6d8a30f4b9c0c6cb810d4dac0235d0cc55f
4
+ data.tar.gz: ed902ddd5a9349009a43d0a883a5526f7097d759e742c6ff43b8baf904765f63
5
5
  SHA512:
6
- metadata.gz: b39b9310b28cd5bd9cfe3ea0511f6c615f3c130060693296e6aa01b18d3c893c9cd1704954133e9655c6a47fbe66f636eabc95c4a012f1e34ae4a0e634f6c0b3
7
- data.tar.gz: 4881137e7cd922d5a9e56bcaec2fd5701b1e21f3e4ed53528585c14a2c24e0f2b90d93b2b36c7327160dae03cdc9c3e0f3a6171abb898d17843de862bf1f02a1
6
+ metadata.gz: 52d08252ebda560e9abf682eb011c5e2281afbf0c3eead4acc650b9af8714555f465ffc9c613318eb2bed9e86caf72edddde1ad8edb5f26aea2233b7ebc38b96
7
+ data.tar.gz: cfdb971e4bdf9d1ce7c830b8f6da93614e630251ca7307f91baddf05353f43e1c1ef51aa84dc3db505ffb8221bf7fde68ee1e6348462e4fd9cacc9c820c2efb8
data/CHANGELOG.md CHANGED
@@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## Unreleased
8
8
 
9
+ ## [0.5.0] - 2023-12-19
10
+
11
+ ### Added
12
+ - Introduce `Physical::Structure` class [#31]
13
+
14
+ ### Changed
15
+ - Use legitimate state/zip in location factory [#30]
16
+
9
17
  ## [0.4.9] - 2023-08-02
10
18
 
11
19
  ### Added
@@ -3,12 +3,13 @@
3
3
  module Physical
4
4
  class Package
5
5
  extend Forwardable
6
- attr_reader :id, :container, :items, :void_fill_density, :items_weight, :used_volume
6
+ attr_reader :id, :container, :items, :void_fill_density, :items_weight, :used_volume, :description
7
7
 
8
- def initialize(id: nil, container: nil, items: [], void_fill_density: Measured::Density(0, :g_ml), dimensions: nil, weight: nil, properties: {})
8
+ def initialize(id: nil, container: nil, items: [], void_fill_density: Measured::Density(0, :g_ml), dimensions: nil, weight: nil, description: nil, properties: {})
9
9
  @id = id || SecureRandom.uuid
10
10
  @void_fill_density = Types::Density[void_fill_density]
11
11
  @container = container || Physical::Box.new(dimensions: dimensions || [], weight: weight || Measured::Weight(0, :g), properties: properties)
12
+ @description = description
12
13
 
13
14
  @items = Set[*items]
14
15
  @items_weight = @items.map(&:weight).reduce(Measured::Weight(0, :g), &:+)
@@ -7,17 +7,23 @@ module Physical
7
7
  :destination,
8
8
  :service_code,
9
9
  :pallets,
10
+ :structures,
10
11
  :packages,
11
12
  :options
12
13
 
13
- def initialize(id: nil, origin: nil, destination: nil, service_code: nil, pallets: [], packages: [], options: {})
14
+ def initialize(id: nil, origin: nil, destination: nil, service_code: nil, pallets: [], structures: [], packages: [], options: {})
14
15
  @id = id || SecureRandom.uuid
15
16
  @origin = origin
16
17
  @destination = destination
17
18
  @service_code = service_code
18
- @pallets = pallets
19
+ @structures = structures
19
20
  @packages = packages
20
21
  @options = options
22
+
23
+ return unless pallets.any?
24
+
25
+ warn "[DEPRECATION] `pallets` is deprecated. Please use `structures` instead."
26
+ @pallets = pallets
21
27
  end
22
28
  end
23
29
  end
@@ -4,15 +4,15 @@ FactoryBot.define do
4
4
  factory :physical_location, class: 'Physical::Location' do
5
5
  transient do
6
6
  country_code { 'US' }
7
- region_code { 'IL' }
7
+ region_code { 'VA' }
8
8
  end
9
9
 
10
10
  name { 'Jane Doe' }
11
11
  company_name { 'Company' }
12
12
  address1 { '11 Lovely Street' }
13
- address2 { 'South' }
13
+ address2 { 'Suite 100' }
14
14
  city { 'Herndon' }
15
- sequence(:zip, 10_001, &:to_s)
15
+ zip { '20170' }
16
16
  phone { '555-555-0199' }
17
17
  email { 'jane@company.com' }
18
18
  region { country.subregions.coded(region_code) }
@@ -4,9 +4,14 @@ FactoryBot.define do
4
4
  factory :physical_shipment, class: "Physical::Shipment" do
5
5
  origin { FactoryBot.build(:physical_location) }
6
6
  destination { FactoryBot.build(:physical_location) }
7
- pallets { build_list(:physical_pallet, 1) }
7
+ pallets { build_list(:physical_pallet, 1) } # deprecated, will be removed
8
8
  packages { build_list(:physical_package, 2) }
9
9
  service_code { "usps_priority_mail" }
10
10
  initialize_with { new(**attributes) }
11
+
12
+ trait :freight do
13
+ structures { build_list(:physical_structure, 1) }
14
+ service_code { "tforce_freight" }
15
+ end
11
16
  end
12
17
  end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
4
+ factory :physical_structure, class: "Physical::Structure" do
5
+ container { FactoryBot.build(:physical_pallet) }
6
+ packages { build_list(:physical_package, 2) }
7
+ initialize_with { new(**attributes) }
8
+ end
9
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Physical
4
+ class Structure
5
+ extend Forwardable
6
+ attr_reader :id, :container, :packages, :packages_weight, :used_volume
7
+
8
+ def initialize(id: nil, container: nil, packages: [], dimensions: nil, weight: nil, properties: {})
9
+ @id = id || SecureRandom.uuid
10
+ @container = container || Physical::Pallet.new(dimensions: dimensions || [], weight: weight || Measured::Weight(0, :g), properties: properties)
11
+
12
+ @packages = Set[*packages]
13
+ @packages_weight = @packages.map(&:weight).reduce(Measured::Weight(0, :g), &:+)
14
+ @used_volume = @packages.map(&:volume).reduce(Measured::Volume(0, :ml), &:+)
15
+ end
16
+
17
+ delegate [:dimensions, :width, :length, :height, :properties, :volume] => :container
18
+
19
+ def <<(other)
20
+ @packages.add(other)
21
+ @packages_weight += other.weight
22
+ @used_volume += other.volume
23
+ end
24
+ alias_method :add, :<<
25
+
26
+ def >>(other)
27
+ @packages.delete(other)
28
+ @packages_weight -= other.weight
29
+ @used_volume -= other.volume
30
+ end
31
+ alias_method :delete, :>>
32
+
33
+ def weight
34
+ container.weight + packages_weight
35
+ end
36
+
37
+ # Cost is optional. We will only return an aggregate if all packages
38
+ # have items value defined. Otherwise we will return nil.
39
+ # @return Money
40
+ def packages_value
41
+ packages_cost = packages.map(&:items_value)
42
+ packages_cost.reduce(&:+) if packages_cost.compact.size == packages_cost.size
43
+ end
44
+
45
+ def remaining_volume
46
+ container.inner_volume - used_volume
47
+ end
48
+
49
+ def density
50
+ return Measured::Density(Float::INFINITY, :g_ml) if container.volume.value.zero?
51
+ return Measured::Density(0.0, :g_ml) if container.volume.value.infinite?
52
+
53
+ Measured::Density(weight.convert_to(:g).value / container.volume.convert_to(:ml).value, :g_ml)
54
+ end
55
+ end
56
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Physical
4
- VERSION = "0.4.9"
4
+ VERSION = "0.5.0"
5
5
  end
data/lib/physical.rb CHANGED
@@ -12,6 +12,7 @@ require "physical/pallet"
12
12
  require "physical/item"
13
13
  require "physical/location"
14
14
  require "physical/shipment"
15
+ require "physical/structure"
15
16
 
16
17
  module Physical
17
18
  # Your code goes here...
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: physical
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.9
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Meyerhoff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-02 00:00:00.000000000 Z
11
+ date: 2023-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: carmen
@@ -207,9 +207,11 @@ files:
207
207
  - lib/physical/spec_support/factories/package_factory.rb
208
208
  - lib/physical/spec_support/factories/pallet_factory.rb
209
209
  - lib/physical/spec_support/factories/shipment_factory.rb
210
+ - lib/physical/spec_support/factories/structure_factory.rb
210
211
  - lib/physical/spec_support/shared_examples.rb
211
212
  - lib/physical/spec_support/shared_examples/a_cuboid.rb
212
213
  - lib/physical/spec_support/shared_examples/has_property_readers.rb
214
+ - lib/physical/structure.rb
213
215
  - lib/physical/test_support.rb
214
216
  - lib/physical/types.rb
215
217
  - lib/physical/version.rb
@@ -233,7 +235,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
233
235
  - !ruby/object:Gem::Version
234
236
  version: '0'
235
237
  requirements: []
236
- rubygems_version: 3.4.10
238
+ rubygems_version: 3.4.22
237
239
  signing_key:
238
240
  specification_version: 4
239
241
  summary: A facade to deal with physical packages