physical 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +1 -1
- data/Rakefile +2 -0
- data/lib/physical/cuboid.rb +7 -5
- data/lib/physical/item.rb +0 -7
- data/lib/physical/location.rb +2 -2
- data/lib/physical/package.rb +15 -3
- data/lib/physical/spec_support/shared_examples.rb +23 -0
- data/lib/physical/version.rb +1 -1
- data/physical.gemspec +2 -2
- metadata +21 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76beac13fca836278bba298bbb217f4dd9cb4b40
|
4
|
+
data.tar.gz: 0351e63dfa2b4af7200662e2f8b8ece442e95fa9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6dc47ed1063302a50ecf4c65898163e94752a5ee776be58ff37663a64dcbfac51c1a7d9296d9a9fe37774c8a6f20c828faf6a6bfad6511ae58470e81c973325e
|
7
|
+
data.tar.gz: e5caf73ede430f01767575bf25b4f0a56101f0ece9d273aacdbad1ecfe70ca0dac4a24e17ddc65df9b425410e0a919d927dc32bbabcbd3a2d8259b1de19758c6
|
data/.circleci/config.yml
CHANGED
data/Rakefile
CHANGED
data/lib/physical/cuboid.rb
CHANGED
@@ -4,17 +4,19 @@ require 'measured'
|
|
4
4
|
|
5
5
|
module Physical
|
6
6
|
class Cuboid
|
7
|
-
attr_reader :dimensions, :weight, :id
|
7
|
+
attr_reader :dimensions, :width, :height, :depth, :weight, :id, :properties
|
8
8
|
|
9
|
-
def initialize(id: nil, dimensions: [], dimension_unit: :cm, weight: 0, weight_unit: :g)
|
9
|
+
def initialize(id: nil, dimensions: [], dimension_unit: :cm, weight: 0, weight_unit: :g, properties: {})
|
10
10
|
@id = id || SecureRandom.uuid
|
11
|
-
@weight = Measured::Weight(weight, weight_unit)
|
12
|
-
@dimensions = dimensions.map { |dimension| Measured::Length.new(dimension, dimension_unit)
|
11
|
+
@weight = Measured::Weight(weight, weight_unit)
|
12
|
+
@dimensions = dimensions.map { |dimension| Measured::Length.new(dimension, dimension_unit) }
|
13
13
|
@dimensions.fill(Measured::Length(self.class::DEFAULT_LENGTH, dimension_unit), @dimensions.length..2)
|
14
|
+
@width, @height, @depth = *@dimensions
|
15
|
+
@properties = properties
|
14
16
|
end
|
15
17
|
|
16
18
|
def volume
|
17
|
-
Measured::Volume(dimensions.map(
|
19
|
+
Measured::Volume(dimensions.map { |d| d.convert_to(:cm).value }.reduce(1, &:*), :ml)
|
18
20
|
end
|
19
21
|
|
20
22
|
def ==(other)
|
data/lib/physical/item.rb
CHANGED
data/lib/physical/location.rb
CHANGED
@@ -44,8 +44,8 @@ module Physical
|
|
44
44
|
|
45
45
|
if region.is_a?(Carmen::Region)
|
46
46
|
@region = region
|
47
|
-
elsif country.is_a?(Carmen::Country)
|
48
|
-
@region = country.subregions.coded(region.to_s.upcase)
|
47
|
+
elsif @country.is_a?(Carmen::Country)
|
48
|
+
@region = @country.subregions.coded(region.to_s.upcase)
|
49
49
|
end
|
50
50
|
|
51
51
|
@name = name
|
data/lib/physical/package.rb
CHANGED
@@ -2,15 +2,18 @@
|
|
2
2
|
|
3
3
|
module Physical
|
4
4
|
class Package
|
5
|
+
extend Forwardable
|
5
6
|
attr_reader :container, :items, :void_fill_density, :id
|
6
7
|
|
7
8
|
def initialize(id: nil, container: Physical::Box.new, items: [], void_fill_density: 0, void_fill_density_unit: :g)
|
8
9
|
@id = id || SecureRandom.uuid
|
9
|
-
@void_fill_density =
|
10
|
+
@void_fill_density = measured_void_fill_density(void_fill_density, void_fill_density_unit)
|
10
11
|
@container = container
|
11
12
|
@items = Set[*items]
|
12
13
|
end
|
13
14
|
|
15
|
+
def_delegator :@container, :dimensions
|
16
|
+
|
14
17
|
def <<(item)
|
15
18
|
@items.add(item)
|
16
19
|
end
|
@@ -20,11 +23,11 @@ module Physical
|
|
20
23
|
end
|
21
24
|
|
22
25
|
def weight
|
23
|
-
container.weight + items.map(&:weight).reduce(&:+) + void_fill_weight
|
26
|
+
container.weight + items.map(&:weight).reduce(Measured::Weight(0, :g), &:+) + void_fill_weight
|
24
27
|
end
|
25
28
|
|
26
29
|
def remaining_volume
|
27
|
-
container.volume - items.map(&:volume).reduce(&:+)
|
30
|
+
container.volume - items.map(&:volume).reduce(Measured::Volume(0, :ml), &:+)
|
28
31
|
end
|
29
32
|
|
30
33
|
def void_fill_weight
|
@@ -32,5 +35,14 @@ module Physical
|
|
32
35
|
|
33
36
|
Measured::Weight(void_fill_density.value * remaining_volume.value, void_fill_density.unit)
|
34
37
|
end
|
38
|
+
|
39
|
+
def measured_void_fill_density(void_fill_density, void_fill_density_unit)
|
40
|
+
case void_fill_density
|
41
|
+
when Measured::Weight
|
42
|
+
void_fill_density
|
43
|
+
else
|
44
|
+
Measured::Weight(void_fill_density, void_fill_density_unit)
|
45
|
+
end
|
46
|
+
end
|
35
47
|
end
|
36
48
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.shared_examples 'a cuboid' do
|
4
|
+
let(:args) { {dimensions: [1.1, 2.2, 3.3], dimension_unit: :cm} }
|
5
|
+
|
6
|
+
it { is_expected.to be_a(Physical::Cuboid) }
|
7
|
+
|
8
|
+
it "has dimensions as Measured::Length objects with rational values" do
|
9
|
+
expect(subject.dimensions).to eq(
|
10
|
+
[
|
11
|
+
Measured::Length.new(1.1, :cm),
|
12
|
+
Measured::Length.new(2.2, :cm),
|
13
|
+
Measured::Length.new(3.3, :cm)
|
14
|
+
]
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "has getter methods for each dimension as Measured::Length object" do
|
19
|
+
expect(subject.width).to eq(Measured::Length.new(1.1, :cm))
|
20
|
+
expect(subject.height).to eq(Measured::Length.new(2.2, :cm))
|
21
|
+
expect(subject.depth).to eq(Measured::Length.new(3.3, :cm))
|
22
|
+
end
|
23
|
+
end
|
data/lib/physical/version.rb
CHANGED
data/physical.gemspec
CHANGED
@@ -21,10 +21,10 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.require_paths = ["lib"]
|
22
22
|
spec.required_ruby_version = '>= 2.4'
|
23
23
|
spec.add_runtime_dependency "carmen", "~> 1.0"
|
24
|
-
spec.add_runtime_dependency "factory_bot", "~> 4.8 "
|
25
24
|
spec.add_runtime_dependency "measured", "~> 2.4.0"
|
26
25
|
|
27
|
-
spec.add_development_dependency "bundler", "
|
26
|
+
spec.add_development_dependency "bundler", [">= 1.16", "< 3"]
|
27
|
+
spec.add_development_dependency "factory_bot", "~> 4.8"
|
28
28
|
spec.add_development_dependency "rake", "~> 10.0"
|
29
29
|
spec.add_development_dependency "rspec", "~> 3.0"
|
30
30
|
end
|
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.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Meyerhoff
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-02-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: carmen
|
@@ -25,47 +25,53 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: measured
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 2.4.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 2.4.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
48
|
-
|
47
|
+
version: '1.16'
|
48
|
+
- - "<"
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '3'
|
51
|
+
type: :development
|
49
52
|
prerelease: false
|
50
53
|
version_requirements: !ruby/object:Gem::Requirement
|
51
54
|
requirements:
|
52
|
-
- - "
|
55
|
+
- - ">="
|
53
56
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
57
|
+
version: '1.16'
|
58
|
+
- - "<"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '3'
|
55
61
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
62
|
+
name: factory_bot
|
57
63
|
requirement: !ruby/object:Gem::Requirement
|
58
64
|
requirements:
|
59
65
|
- - "~>"
|
60
66
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
67
|
+
version: '4.8'
|
62
68
|
type: :development
|
63
69
|
prerelease: false
|
64
70
|
version_requirements: !ruby/object:Gem::Requirement
|
65
71
|
requirements:
|
66
72
|
- - "~>"
|
67
73
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
74
|
+
version: '4.8'
|
69
75
|
- !ruby/object:Gem::Dependency
|
70
76
|
name: rake
|
71
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -127,6 +133,7 @@ files:
|
|
127
133
|
- lib/physical/spec_support/factories/location_factory.rb
|
128
134
|
- lib/physical/spec_support/factories/package_factory.rb
|
129
135
|
- lib/physical/spec_support/factories/shipment_factory.rb
|
136
|
+
- lib/physical/spec_support/shared_examples.rb
|
130
137
|
- lib/physical/version.rb
|
131
138
|
- physical.gemspec
|
132
139
|
homepage: https://github.com/mamhoff/physical
|