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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b7695f39bf2488e6b55a5fc20db7c5fac96a3c4cc5cdf3cb2849b36eb6b21253
4
- data.tar.gz: 11b56feb9a761c82b31ed131fa3035675fe6c592122e7e1b1c358f34614fecb6
3
+ metadata.gz: c3e8f33230d128b7c587948a392f750872681530e3780b549ed0fc6c048bde9f
4
+ data.tar.gz: 344d927c6b5c36317792de56f4d84b4d52e2a7929ee89a1030500218ee0bb942
5
5
  SHA512:
6
- metadata.gz: 9f723bd0ba306e8caac4f461ee2ebad857716684e4d955a4a49c42d40ee4768d19e69c4598ff1c9bd6e0990b411a1805be06f19ae0ebd1189b46064945e0e5ea
7
- data.tar.gz: 8b9dd20c1931d6932559034341b88077b9642f83ccb16cd759e090e5a44802f963fe4cf6c1f476cac302b9b853757506f66c776de9738996f4b9fcf12f8b825a
6
+ metadata.gz: 10644a7dfaeebaac09b8f5c77eeb6942dae9092e1ed68cb7aec8229b597ebde03396ae9f104a484e4f799b8c0b0021f1f4a11229aa29989b89e43bce88b65f8d
7
+ data.tar.gz: b6b58d4846a5ea0f833601ecbbe20fc054e2467e1a3bb1e7fd95ac4eb540526a1fc9db12c5da32667f630a287d6063230a58850c0a6e63b316e7d32b85351ca7
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- boxxer (0.1.3)
4
+ boxxer (0.1.4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -1,55 +1,10 @@
1
- require 'boxxer/container'
1
+ require 'boxxer/handler'
2
2
  require 'boxxer/version'
3
3
 
4
4
  module Boxxer
5
5
  class Error < StandardError; end
6
6
 
7
- class Arranger
8
- attr_reader :containers
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
@@ -1,3 +1,3 @@
1
1
  module Boxxer
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.4'
3
3
  end
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.3
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-07 00:00:00.000000000 Z
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.6
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