boxxer 0.1.3 → 0.1.4
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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/boxxer.rb +3 -48
- data/lib/boxxer/handler.rb +53 -0
- data/lib/boxxer/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3e8f33230d128b7c587948a392f750872681530e3780b549ed0fc6c048bde9f
|
4
|
+
data.tar.gz: 344d927c6b5c36317792de56f4d84b4d52e2a7929ee89a1030500218ee0bb942
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10644a7dfaeebaac09b8f5c77eeb6942dae9092e1ed68cb7aec8229b597ebde03396ae9f104a484e4f799b8c0b0021f1f4a11229aa29989b89e43bce88b65f8d
|
7
|
+
data.tar.gz: b6b58d4846a5ea0f833601ecbbe20fc054e2467e1a3bb1e7fd95ac4eb540526a1fc9db12c5da32667f630a287d6063230a58850c0a6e63b316e7d32b85351ca7
|
data/Gemfile.lock
CHANGED
data/lib/boxxer.rb
CHANGED
@@ -1,55 +1,10 @@
|
|
1
|
-
require 'boxxer/
|
1
|
+
require 'boxxer/handler'
|
2
2
|
require 'boxxer/version'
|
3
3
|
|
4
4
|
module Boxxer
|
5
5
|
class Error < StandardError; end
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
def initialize(containers:, weights:)
|
11
|
-
@available_containers = containers.sort { |container| container[:net_limit] }.reverse
|
12
|
-
@largest_container = @available_containers.last
|
13
|
-
@weights = weights.sort.reverse
|
14
|
-
@containers = []
|
15
|
-
end
|
16
|
-
|
17
|
-
def call
|
18
|
-
raise Error, "Largest container net_limit is #{@largest_container[:net_limit]}, but maximum weight is #{@weights.max}" if invalid_options?
|
19
|
-
until @weights.empty? do
|
20
|
-
container = Container.new(matching_container)
|
21
|
-
complete_container(container)
|
22
|
-
@containers << container
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def total_gross_weight
|
27
|
-
@containers.sum(&:gross_weight)
|
28
|
-
end
|
29
|
-
|
30
|
-
def total_net_weight
|
31
|
-
@containers.sum(&:net_weight)
|
32
|
-
end
|
33
|
-
|
34
|
-
def container_count
|
35
|
-
@containers.count
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
def complete_container(container)
|
41
|
-
loop do
|
42
|
-
fittable_weight = @weights.find { |weight| container.fittable?(weight) }
|
43
|
-
fittable_weight.nil? ? break : container.add_weight(@weights.delete_at(@weights.index(fittable_weight)))
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def invalid_options?
|
48
|
-
@weights.max > @largest_container[:net_limit]
|
49
|
-
end
|
50
|
-
|
51
|
-
def matching_container
|
52
|
-
@available_containers.find { |container| container[:net_limit] >= @weights.sum } || @largest_container
|
53
|
-
end
|
7
|
+
def self.call(options = {})
|
8
|
+
Handler.new(options).call
|
54
9
|
end
|
55
10
|
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'boxxer/container'
|
2
|
+
|
3
|
+
module Boxxer
|
4
|
+
class Handler
|
5
|
+
attr_reader :containers
|
6
|
+
|
7
|
+
def initialize(containers:, weights:)
|
8
|
+
@available_containers = containers.sort { |container| container[:net_limit] }.reverse
|
9
|
+
@largest_container = @available_containers.last
|
10
|
+
@weights = weights.sort.reverse
|
11
|
+
@containers = []
|
12
|
+
end
|
13
|
+
|
14
|
+
def call
|
15
|
+
raise Error, "Largest container net_limit is #{@largest_container[:net_limit]}, but maximum weight is #{@weights.max}" if invalid_options?
|
16
|
+
until @weights.empty? do
|
17
|
+
container = Container.new(matching_container)
|
18
|
+
complete_container(container)
|
19
|
+
@containers << container
|
20
|
+
end
|
21
|
+
self
|
22
|
+
end
|
23
|
+
|
24
|
+
def total_gross_weight
|
25
|
+
@containers.sum(&:gross_weight).truncate(3)
|
26
|
+
end
|
27
|
+
|
28
|
+
def total_net_weight
|
29
|
+
@containers.sum(&:net_weight).truncate(3)
|
30
|
+
end
|
31
|
+
|
32
|
+
def container_count
|
33
|
+
@containers.count
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def complete_container(container)
|
39
|
+
loop do
|
40
|
+
fittable_weight = @weights.find { |weight| container.fittable?(weight) }
|
41
|
+
fittable_weight.nil? ? break : container.add_weight(@weights.delete_at(@weights.index(fittable_weight)))
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def invalid_options?
|
46
|
+
@weights.max > @largest_container[:net_limit]
|
47
|
+
end
|
48
|
+
|
49
|
+
def matching_container
|
50
|
+
@available_containers.find { |container| container[:net_limit] >= @weights.sum } || @largest_container
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/boxxer/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: boxxer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitry Sivoglaz
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-06-
|
11
|
+
date: 2020-06-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: awesome_print
|
@@ -101,6 +101,7 @@ files:
|
|
101
101
|
- boxxer.gemspec
|
102
102
|
- lib/boxxer.rb
|
103
103
|
- lib/boxxer/container.rb
|
104
|
+
- lib/boxxer/handler.rb
|
104
105
|
- lib/boxxer/version.rb
|
105
106
|
homepage:
|
106
107
|
licenses:
|
@@ -121,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
122
|
- !ruby/object:Gem::Version
|
122
123
|
version: '0'
|
123
124
|
requirements: []
|
124
|
-
rubygems_version: 3.0.
|
125
|
+
rubygems_version: 3.0.8
|
125
126
|
signing_key:
|
126
127
|
specification_version: 4
|
127
128
|
summary: Picking containers, boxes, cartons, packages based on items weight
|