order_optimizer 0.4.0 → 0.4.1
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 +63 -0
- data/.gitignore +1 -0
- data/CHANGELOG.md +6 -0
- data/README.md +15 -4
- data/lib/order_optimizer.rb +1 -1
- data/lib/order_optimizer/sku.rb +7 -7
- data/lib/order_optimizer/version.rb +1 -1
- data/order_optimizer.gemspec +3 -3
- metadata +9 -9
- data/Gemfile.lock +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5868b03e4f28cfec6001c9e53e61ffba0907c6d626d4ee950596bf4b1f154075
|
4
|
+
data.tar.gz: 739453efda8bcfe9e015f91a47b0cf8945d0c9270fe8f18dc6241a71c5d35e63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eebd782f5bc6971227292700da42edb7c30a3bca2d19573f65f901311b708aa91fd422ad1ca51a17798d28351e89a020eb1857b7ff7671892874f9e67fbe1429
|
7
|
+
data.tar.gz: d4f80534e745ed6723468c7bf7b49ce5fd5d45fb6db915b756601aa7b00894d10550baeb16bba5da96f4bc24c01e5638ab7ab79ac07ca6eb0bb6576aa4648663
|
@@ -0,0 +1,63 @@
|
|
1
|
+
version: 2.1
|
2
|
+
jobs:
|
3
|
+
test:
|
4
|
+
docker:
|
5
|
+
- image: circleci/ruby:3.0
|
6
|
+
|
7
|
+
working_directory: ~/repo
|
8
|
+
|
9
|
+
steps:
|
10
|
+
- checkout
|
11
|
+
|
12
|
+
- restore_cache:
|
13
|
+
keys:
|
14
|
+
- v1-dependencies-{{ checksum "order_optimizer.gemspec" }}
|
15
|
+
# fallback to using the latest cache if no exact match is found
|
16
|
+
- v1-dependencies-
|
17
|
+
|
18
|
+
- run:
|
19
|
+
name: install dependencies
|
20
|
+
command: bundle install --jobs=4 --retry=3 --path vendor/bundle
|
21
|
+
|
22
|
+
- save_cache:
|
23
|
+
paths:
|
24
|
+
- ./vendor/bundle
|
25
|
+
key: v1-dependencies-{{ checksum "order_optimizer.gemspec" }}
|
26
|
+
|
27
|
+
- run:
|
28
|
+
name: run tests
|
29
|
+
command: bundle exec rake
|
30
|
+
|
31
|
+
publish:
|
32
|
+
docker:
|
33
|
+
- image: circleci/ruby:3.0
|
34
|
+
working_directory: ~/repo
|
35
|
+
steps:
|
36
|
+
- checkout
|
37
|
+
- run:
|
38
|
+
name: Build package
|
39
|
+
command: gem build order_optimizer.gemspec
|
40
|
+
- run:
|
41
|
+
name: Push package
|
42
|
+
command: |
|
43
|
+
VERSION=$(ruby -r "./lib/order_optimizer/version.rb" -e "print OrderOptimizer::VERSION")
|
44
|
+
gem push order_optimizer-${VERSION}.gem
|
45
|
+
|
46
|
+
workflows:
|
47
|
+
default:
|
48
|
+
jobs:
|
49
|
+
- test:
|
50
|
+
filters:
|
51
|
+
tags:
|
52
|
+
only: /.*/
|
53
|
+
branches:
|
54
|
+
only: /.*/
|
55
|
+
- publish:
|
56
|
+
context:
|
57
|
+
- rubygems-push
|
58
|
+
requires: [test]
|
59
|
+
filters:
|
60
|
+
tags:
|
61
|
+
only: /^v.*/
|
62
|
+
branches:
|
63
|
+
ignore: /.*/
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# OrderOptimizer Gem Changelog
|
2
2
|
|
3
|
+
## 0.4.1 (2021-02-15)
|
4
|
+
|
5
|
+
- Fix issue with floating point conversion [#3]
|
6
|
+
|
3
7
|
## 0.4.0 (2020-12-11)
|
4
8
|
|
5
9
|
- Add `possible_orders` method to find all possible orders
|
@@ -18,3 +22,5 @@
|
|
18
22
|
- Add support for discounts when ordering a minimum quantity
|
19
23
|
|
20
24
|
## 0.1.0 First release
|
25
|
+
|
26
|
+
[#3]: https://github.com/zaikio/order_optimizer/pull/3
|
data/README.md
CHANGED
@@ -119,11 +119,22 @@ order_optimizer.possible_orders(required_qty: 10).map(&:skus)
|
|
119
119
|
|
120
120
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
121
121
|
|
122
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
123
|
-
|
124
122
|
## Contributing
|
125
123
|
|
126
|
-
Bug reports and pull requests are welcome on GitHub at
|
124
|
+
Bug reports and pull requests are welcome on GitHub at
|
125
|
+
https://github.com/zaikio/order_optimizer. This project is intended to be a safe,
|
126
|
+
welcoming space for collaboration, and contributors are expected to adhere to the
|
127
|
+
[Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
128
|
+
|
129
|
+
- Make your changes and submit a pull request for them
|
130
|
+
- Make sure to update `CHANGELOG.md`
|
131
|
+
|
132
|
+
To release a new version of the gem:
|
133
|
+
- Update the version in `lib/order_optimizer/version.rb`
|
134
|
+
- Update `CHANGELOG.md` to include the new version and its release date
|
135
|
+
- Commit and push your changes
|
136
|
+
- Create a [new release on GitHub](https://github.com/zaikio/order_optimizer/releases/new)
|
137
|
+
- CircleCI will build the Gem package and push it Rubygems for you
|
127
138
|
|
128
139
|
## License
|
129
140
|
|
@@ -131,4 +142,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
131
142
|
|
132
143
|
## Code of Conduct
|
133
144
|
|
134
|
-
Everyone interacting in the OrderOptimizer project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
145
|
+
Everyone interacting in the OrderOptimizer project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/zaikio/order_optimizer/blob/master/CODE_OF_CONDUCT.md).
|
data/lib/order_optimizer.rb
CHANGED
@@ -56,7 +56,7 @@ class OrderOptimizer
|
|
56
56
|
count, remainder = quantity.divmod(sku.quantity)
|
57
57
|
|
58
58
|
if sku.min_quantity && count * sku.quantity < sku.min_quantity
|
59
|
-
new_count = (sku.min_quantity
|
59
|
+
new_count = (sku.min_quantity / sku.quantity).ceil
|
60
60
|
remainder -= (new_count - count) * sku.quantity
|
61
61
|
[new_count, [remainder, 0].max]
|
62
62
|
else
|
data/lib/order_optimizer/sku.rb
CHANGED
@@ -4,18 +4,18 @@ class OrderOptimizer
|
|
4
4
|
|
5
5
|
def initialize(id, quantity:, price_per_sku: nil, price_per_unit: nil, min_quantity: nil)
|
6
6
|
@id = id
|
7
|
-
@quantity = quantity
|
8
|
-
@min_quantity = min_quantity
|
9
|
-
|
10
|
-
@price_per_unit = BigDecimal(price_per_unit, 2) if price_per_unit
|
11
|
-
@price_per_sku = BigDecimal(price_per_sku, 2) if price_per_sku
|
7
|
+
@quantity = BigDecimal(quantity, 2)
|
8
|
+
@min_quantity = BigDecimal(min_quantity, 2) if min_quantity
|
12
9
|
|
13
10
|
unless price_per_unit || price_per_sku
|
14
11
|
raise ':price_per_sku or :price_per_unit must be set'
|
15
12
|
end
|
16
13
|
|
17
|
-
@price_per_unit
|
18
|
-
@
|
14
|
+
@price_per_unit = BigDecimal(price_per_unit, 2) if price_per_unit
|
15
|
+
@price_per_unit ||= BigDecimal(price_per_sku, 2) / quantity
|
16
|
+
|
17
|
+
@price_per_sku = BigDecimal(price_per_sku, 2) if price_per_sku
|
18
|
+
@price_per_sku ||= quantity * price_per_unit
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
data/order_optimizer.gemspec
CHANGED
@@ -7,13 +7,13 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.version = OrderOptimizer::VERSION
|
8
8
|
|
9
9
|
spec.authors = ["crispymtn", "Martin Spickermann", "Maurice Vogel"]
|
10
|
-
spec.email = ["op@
|
11
|
-
spec.homepage = "https://github.com/
|
10
|
+
spec.email = ["op@zaikio.com", "spickermann@gmail.com"]
|
11
|
+
spec.homepage = "https://github.com/zaikio/order_optimizer"
|
12
12
|
spec.license = "MIT"
|
13
13
|
spec.summary = "Helps to optimize orders if the goods are offered in different pack sizes and in different discount levels."
|
14
14
|
|
15
15
|
|
16
|
-
spec.metadata["changelog_uri"] = "https://github.com/
|
16
|
+
spec.metadata["changelog_uri"] = "https://github.com/zaikio/order_optimizer/blob/master/CHANGELOG.md"
|
17
17
|
spec.metadata["homepage_uri"] = spec.homepage
|
18
18
|
spec.metadata["source_code_uri"] = spec.homepage
|
19
19
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: order_optimizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- crispymtn
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2021-02-15 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|
@@ -56,18 +56,18 @@ dependencies:
|
|
56
56
|
version: '0'
|
57
57
|
description:
|
58
58
|
email:
|
59
|
-
- op@
|
59
|
+
- op@zaikio.com
|
60
60
|
- spickermann@gmail.com
|
61
61
|
executables: []
|
62
62
|
extensions: []
|
63
63
|
extra_rdoc_files: []
|
64
64
|
files:
|
65
|
+
- ".circleci/config.yml"
|
65
66
|
- ".gitignore"
|
66
67
|
- ".travis.yml"
|
67
68
|
- CHANGELOG.md
|
68
69
|
- CODE_OF_CONDUCT.md
|
69
70
|
- Gemfile
|
70
|
-
- Gemfile.lock
|
71
71
|
- LICENSE.txt
|
72
72
|
- README.md
|
73
73
|
- Rakefile
|
@@ -79,13 +79,13 @@ files:
|
|
79
79
|
- lib/order_optimizer/sku.rb
|
80
80
|
- lib/order_optimizer/version.rb
|
81
81
|
- order_optimizer.gemspec
|
82
|
-
homepage: https://github.com/
|
82
|
+
homepage: https://github.com/zaikio/order_optimizer
|
83
83
|
licenses:
|
84
84
|
- MIT
|
85
85
|
metadata:
|
86
|
-
changelog_uri: https://github.com/
|
87
|
-
homepage_uri: https://github.com/
|
88
|
-
source_code_uri: https://github.com/
|
86
|
+
changelog_uri: https://github.com/zaikio/order_optimizer/blob/master/CHANGELOG.md
|
87
|
+
homepage_uri: https://github.com/zaikio/order_optimizer
|
88
|
+
source_code_uri: https://github.com/zaikio/order_optimizer
|
89
89
|
post_install_message:
|
90
90
|
rdoc_options: []
|
91
91
|
require_paths:
|
@@ -101,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
101
|
- !ruby/object:Gem::Version
|
102
102
|
version: '0'
|
103
103
|
requirements: []
|
104
|
-
rubygems_version: 3.
|
104
|
+
rubygems_version: 3.2.3
|
105
105
|
signing_key:
|
106
106
|
specification_version: 4
|
107
107
|
summary: Helps to optimize orders if the goods are offered in different pack sizes
|
data/Gemfile.lock
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
order_optimizer (0.4.0)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: https://rubygems.org/
|
8
|
-
specs:
|
9
|
-
minitest (5.13.0)
|
10
|
-
rake (13.0.1)
|
11
|
-
|
12
|
-
PLATFORMS
|
13
|
-
ruby
|
14
|
-
|
15
|
-
DEPENDENCIES
|
16
|
-
bundler
|
17
|
-
minitest
|
18
|
-
order_optimizer!
|
19
|
-
rake
|
20
|
-
|
21
|
-
BUNDLED WITH
|
22
|
-
2.1.4
|