physical 0.4.9 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/lib/physical/package.rb +3 -2
- data/lib/physical/shipment.rb +5 -2
- data/lib/physical/spec_support/factories/location_factory.rb +3 -3
- data/lib/physical/spec_support/factories/shipment_factory.rb +5 -1
- data/lib/physical/spec_support/factories/structure_factory.rb +9 -0
- data/lib/physical/structure.rb +56 -0
- data/lib/physical/version.rb +1 -1
- data/lib/physical.rb +1 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27de598d29f3754f4a2f4676208da48ba8d83b4e59662c5bd267dffb3ccdee58
|
4
|
+
data.tar.gz: 38cc5da575f4e56cf001370aaea5fd906b82373f75fa6880d804fa20e1b828b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f80884f5e7333d29be10b70e27e683865e0a0ac1f43cfbb464d13008a482ea57932ccbd963599f3412563b556d535de54c43ab21ffb7b8ad0bac2d859895e26
|
7
|
+
data.tar.gz: abfb28ea0aa1fa6fdcfb8e4b31e7b5412d743a45edc4c22cd71d1b8146cdac741b5da69f362a573ac34985628e208e92c8c442a7de7aaf4e615f4ea6398e404e
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## Unreleased
|
8
8
|
|
9
|
+
## [0.5.1] - 2023-12-19
|
10
|
+
|
11
|
+
### Changed
|
12
|
+
- Better pallet deprecations [#32]
|
13
|
+
|
14
|
+
## [0.5.0] - 2023-12-19
|
15
|
+
|
16
|
+
### Added
|
17
|
+
- Introduce `Physical::Structure` class [#31]
|
18
|
+
|
19
|
+
### Changed
|
20
|
+
- Use legitimate state/zip in location factory [#30]
|
21
|
+
|
9
22
|
## [0.4.9] - 2023-08-02
|
10
23
|
|
11
24
|
### Added
|
data/lib/physical/package.rb
CHANGED
@@ -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), &:+)
|
data/lib/physical/shipment.rb
CHANGED
@@ -7,17 +7,20 @@ 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
|
-
@
|
19
|
+
@structures = structures
|
19
20
|
@packages = packages
|
20
21
|
@options = options
|
22
|
+
@pallets = pallets
|
23
|
+
warn "[DEPRECATION] `pallets` is deprecated. Please use `structures` instead." if pallets.any?
|
21
24
|
end
|
22
25
|
end
|
23
26
|
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 { '
|
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 { '
|
13
|
+
address2 { 'Suite 100' }
|
14
14
|
city { 'Herndon' }
|
15
|
-
|
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,13 @@ 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) }
|
8
7
|
packages { build_list(:physical_package, 2) }
|
9
8
|
service_code { "usps_priority_mail" }
|
10
9
|
initialize_with { new(**attributes) }
|
10
|
+
|
11
|
+
trait :freight do
|
12
|
+
structures { build_list(:physical_structure, 1) }
|
13
|
+
service_code { "tforce_freight" }
|
14
|
+
end
|
11
15
|
end
|
12
16
|
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
|
data/lib/physical/version.rb
CHANGED
data/lib/physical.rb
CHANGED
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
|
+
version: 0.5.1
|
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-
|
11
|
+
date: 2023-12-20 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.
|
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
|