physical 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4af0a4a737e1d5585f7770e4f27a57c22ef2163f
4
+ data.tar.gz: b15c1709a756d83168bb2bd442922c5111dff5ab
5
+ SHA512:
6
+ metadata.gz: d1e3b5f4546d845e6eee5b94872048c2daac05c9fbd14f410a9fa5ab938f14cfdd081331732e6aba0e5c929ed6e3171b24a955ada2ce2a98e2dc08d28f9c7ae8
7
+ data.tar.gz: 47352b147c34e80078e8eba73c381d2893813bb9867262c474285a63964fdbf812709ee933d3313b40d8dfbb16440461af0d0a0676bf2855bfea0d9349747870
@@ -0,0 +1,58 @@
1
+ # Ruby CircleCI 2.0 configuration file
2
+ #
3
+ # Check https://circleci.com/docs/2.0/language-ruby/ for more details
4
+ #
5
+ version: 2
6
+ jobs:
7
+ build:
8
+ docker:
9
+ # specify the version you desire here
10
+ - image: circleci/ruby:2.4.1-node-browsers
11
+
12
+ # Specify service dependencies here if necessary
13
+ # CircleCI maintains a library of pre-built images
14
+ # documented at https://circleci.com/docs/2.0/circleci-images/
15
+ # - image: circleci/postgres:9.4
16
+
17
+ working_directory: ~/repo
18
+
19
+ steps:
20
+ - checkout
21
+
22
+ # Download and cache dependencies
23
+ - restore_cache:
24
+ keys:
25
+ - v1-dependencies-{{ checksum "physical.gemspec" }}
26
+ # fallback to using the latest cache if no exact match is found
27
+ - v1-dependencies-
28
+
29
+ - run:
30
+ name: install dependencies
31
+ command: |
32
+ gem install bundler
33
+ bundle install --jobs=4 --retry=3 --path vendor/bundle
34
+
35
+ - save_cache:
36
+ paths:
37
+ - ./vendor/bundle
38
+ key: v1-dependencies-{{ checksum "Gemfile.lock" }}
39
+
40
+ # run tests!
41
+ - run:
42
+ name: run tests
43
+ command: |
44
+ mkdir /tmp/test-results
45
+ TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
46
+
47
+ bundle exec rspec --format progress \
48
+ --format RspecJunitFormatter \
49
+ --out /tmp/test-results/rspec.xml \
50
+ --format progress \
51
+ $TEST_FILES
52
+
53
+ # collect reports
54
+ - store_test_results:
55
+ path: /tmp/test-results
56
+ - store_artifacts:
57
+ path: /tmp/test-results
58
+ destination: test-results
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,321 @@
1
+ AllCops:
2
+ Exclude:
3
+ - Gemfile
4
+ - Rakefile
5
+ - bin/*
6
+ - vendor/**/*
7
+
8
+ Layout/EmptyLinesAroundBlockBody:
9
+ Enabled: false
10
+
11
+ Layout/EmptyLinesAroundModuleBody:
12
+ Enabled: false
13
+
14
+ Layout/EmptyLinesAroundClassBody:
15
+ Enabled: false
16
+
17
+ Layout/EmptyLinesAroundMethodBody:
18
+ Enabled: false
19
+
20
+ Naming/MemoizedInstanceVariableName:
21
+ Enabled: false
22
+
23
+ Style/RedundantSelf:
24
+ Enabled: false
25
+
26
+ CollectionMethods:
27
+ Enabled: false
28
+
29
+ # Sometimes I believe this reads better
30
+ # This also causes spacing issues on multi-line fixes
31
+ Style/BracesAroundHashParameters:
32
+ Enabled: false
33
+
34
+ # We use class vars and will have to continue doing so for compatability
35
+ Style/ClassVars:
36
+ Enabled: false
37
+
38
+ # We need these names for backwards compatability
39
+ Naming/PredicateName:
40
+ Enabled: false
41
+
42
+ Naming/AccessorMethodName:
43
+ Enabled: false
44
+
45
+ # This has been used for customization
46
+ Style/MutableConstant:
47
+ Enabled: false
48
+
49
+ # `something.count > 0` is often used in Solidus admin and IMO better to read then `something.count.positive?`
50
+ Style/NumericPredicate:
51
+ Enabled: false
52
+
53
+ Style/ClassAndModuleChildren:
54
+ Enabled: false
55
+
56
+ Style/EmptyElse:
57
+ Enabled: false
58
+
59
+ Style/GuardClause:
60
+ Enabled: false
61
+
62
+ Style/Next:
63
+ Enabled: false
64
+
65
+ Style/WordArray:
66
+ Enabled: false
67
+
68
+ Style/ConditionalAssignment:
69
+ Enabled: false
70
+
71
+ Performance/Count:
72
+ Enabled: false
73
+
74
+ Style/RaiseArgs:
75
+ Enabled: false
76
+
77
+ Naming/BinaryOperatorParameterName:
78
+ Enabled: false
79
+
80
+ # We can use good judgement here
81
+ Style/RegexpLiteral:
82
+ Enabled: false
83
+
84
+ # Unicode comments are useful
85
+ Style/AsciiComments:
86
+ Enabled: false
87
+
88
+ Layout/EndAlignment:
89
+ Enabled: false
90
+
91
+ Layout/ElseAlignment:
92
+ Enabled: false
93
+
94
+ Layout/IndentationWidth:
95
+ Enabled: false
96
+
97
+ Layout/AlignParameters:
98
+ Enabled: false
99
+
100
+ Layout/ClosingParenthesisIndentation:
101
+ Enabled: false
102
+
103
+ Layout/MultilineMethodCallIndentation:
104
+ Enabled: false
105
+
106
+ Layout/IndentArray:
107
+ Enabled: false
108
+
109
+ Layout/IndentHash:
110
+ Enabled: false
111
+
112
+ Layout/AlignHash:
113
+ Enabled: false
114
+
115
+ Style/TrailingCommaInArguments:
116
+ Enabled: false
117
+
118
+ Style/TrailingCommaInArrayLiteral:
119
+ Enabled: false
120
+
121
+ Style/TrailingCommaInHashLiteral:
122
+ Enabled: false
123
+
124
+ Layout/SpaceInsideHashLiteralBraces:
125
+ Enabled: false
126
+
127
+ # Symbol Arrays are ok and the %i syntax widely unknown
128
+ Style/SymbolArray:
129
+ Enabled: false
130
+
131
+ Rails/DynamicFindBy:
132
+ Whitelist:
133
+ - find_by_param
134
+ - find_by_param!
135
+
136
+ # We use a lot of
137
+ #
138
+ # expect {
139
+ # something
140
+ # }.to { happen }
141
+ #
142
+ # syntax in the specs files.
143
+ Lint/AmbiguousBlockAssociation:
144
+ Exclude:
145
+ - 'spec/**/*'
146
+
147
+ # We use eval to add common_spree_dependencies into the Gemfiles of each of our gems
148
+ Security/Eval:
149
+ Exclude:
150
+ - 'Gemfile'
151
+ - '*/Gemfile'
152
+
153
+ Naming/VariableNumber:
154
+ Enabled: false
155
+
156
+ # Write empty methods as you wish.
157
+ Style/EmptyMethod:
158
+ Enabled: false
159
+
160
+ # The Rails Guides are in contradiction with this cop.
161
+ Style/FormatStringToken:
162
+ Exclude:
163
+ - 'config/routes.rb'
164
+
165
+ # From http://relaxed.ruby.style/
166
+
167
+ Style/Alias:
168
+ Enabled: false
169
+ StyleGuide: http://relaxed.ruby.style/#stylealias
170
+
171
+ Style/BeginBlock:
172
+ Enabled: false
173
+ StyleGuide: http://relaxed.ruby.style/#stylebeginblock
174
+
175
+ Style/BlockDelimiters:
176
+ Enabled: false
177
+ StyleGuide: http://relaxed.ruby.style/#styleblockdelimiters
178
+
179
+ Style/Documentation:
180
+ Enabled: false
181
+ StyleGuide: http://relaxed.ruby.style/#styledocumentation
182
+
183
+ Layout/DotPosition:
184
+ EnforcedStyle: trailing
185
+ Enabled: true
186
+ StyleGuide: http://relaxed.ruby.style/#styledotposition
187
+
188
+ Style/DoubleNegation:
189
+ Enabled: false
190
+ StyleGuide: http://relaxed.ruby.style/#styledoublenegation
191
+
192
+ Style/EndBlock:
193
+ Enabled: false
194
+ StyleGuide: http://relaxed.ruby.style/#styleendblock
195
+
196
+ Style/FormatString:
197
+ Enabled: false
198
+ StyleGuide: http://relaxed.ruby.style/#styleformatstring
199
+
200
+ Style/IfUnlessModifier:
201
+ Enabled: false
202
+ StyleGuide: http://relaxed.ruby.style/#styleifunlessmodifier
203
+
204
+ Style/Lambda:
205
+ Enabled: false
206
+ StyleGuide: http://relaxed.ruby.style/#stylelambda
207
+
208
+ Style/ModuleFunction:
209
+ Enabled: false
210
+ StyleGuide: http://relaxed.ruby.style/#stylemodulefunction
211
+
212
+ Style/MultilineBlockChain:
213
+ Enabled: false
214
+ StyleGuide: http://relaxed.ruby.style/#stylemultilineblockchain
215
+
216
+ Style/NegatedIf:
217
+ Enabled: false
218
+ StyleGuide: http://relaxed.ruby.style/#stylenegatedif
219
+
220
+ Style/NegatedWhile:
221
+ Enabled: false
222
+ StyleGuide: http://relaxed.ruby.style/#stylenegatedwhile
223
+
224
+ Style/ParallelAssignment:
225
+ Enabled: false
226
+ StyleGuide: http://relaxed.ruby.style/#styleparallelassignment
227
+
228
+ Style/PercentLiteralDelimiters:
229
+ Enabled: false
230
+ StyleGuide: http://relaxed.ruby.style/#stylepercentliteraldelimiters
231
+
232
+ Style/PerlBackrefs:
233
+ Enabled: false
234
+ StyleGuide: http://relaxed.ruby.style/#styleperlbackrefs
235
+
236
+ Style/Semicolon:
237
+ Enabled: false
238
+ StyleGuide: http://relaxed.ruby.style/#stylesemicolon
239
+
240
+ Style/SignalException:
241
+ Enabled: false
242
+ StyleGuide: http://relaxed.ruby.style/#stylesignalexception
243
+
244
+ Style/SingleLineBlockParams:
245
+ Enabled: false
246
+ StyleGuide: http://relaxed.ruby.style/#stylesinglelineblockparams
247
+
248
+ Style/SingleLineMethods:
249
+ Enabled: false
250
+ StyleGuide: http://relaxed.ruby.style/#stylesinglelinemethods
251
+
252
+ Layout/SpaceBeforeBlockBraces:
253
+ Enabled: false
254
+ StyleGuide: http://relaxed.ruby.style/#stylespacebeforeblockbraces
255
+
256
+ Layout/SpaceInsideParens:
257
+ Enabled: false
258
+ StyleGuide: http://relaxed.ruby.style/#stylespaceinsideparens
259
+
260
+ Style/SpecialGlobalVars:
261
+ Enabled: false
262
+ StyleGuide: http://relaxed.ruby.style/#stylespecialglobalvars
263
+
264
+ Style/StringLiterals:
265
+ Enabled: false
266
+ StyleGuide: http://relaxed.ruby.style/#stylestringliterals
267
+
268
+ Style/SymbolProc:
269
+ Enabled: false
270
+
271
+ Style/WhileUntilModifier:
272
+ Enabled: false
273
+ StyleGuide: http://relaxed.ruby.style/#stylewhileuntilmodifier
274
+
275
+ Lint/AmbiguousRegexpLiteral:
276
+ Enabled: false
277
+ StyleGuide: http://relaxed.ruby.style/#lintambiguousregexpliteral
278
+
279
+ Lint/AssignmentInCondition:
280
+ Enabled: true
281
+ StyleGuide: http://relaxed.ruby.style/#lintassignmentincondition
282
+
283
+ Metrics/AbcSize:
284
+ Enabled: false
285
+
286
+ Metrics/BlockNesting:
287
+ Enabled: false
288
+
289
+ Metrics/ClassLength:
290
+ Enabled: false
291
+
292
+ Metrics/ModuleLength:
293
+ Enabled: false
294
+
295
+ Metrics/BlockLength:
296
+ Enabled: false
297
+
298
+ Metrics/CyclomaticComplexity:
299
+ Enabled: false
300
+
301
+ Metrics/LineLength:
302
+ Enabled: true
303
+ Max: 120
304
+ Exclude:
305
+ - 'spec/**/*'
306
+
307
+ Metrics/MethodLength:
308
+ Enabled: false
309
+ Max: 25
310
+
311
+ Metrics/ParameterLists:
312
+ Enabled: false
313
+
314
+ Metrics/PerceivedComplexity:
315
+ Enabled: false
316
+
317
+ Bundler/OrderedGems:
318
+ Enabled: false
319
+
320
+ Style/NumericLiterals:
321
+ Enabled: false
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.4.4
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.4
5
+ before_install: gem install bundler -v 1.16.1
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at mamhoff@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in physical.gemspec
6
+ gemspec
7
+
8
+ group :test do
9
+ gem 'rspec_junit_formatter'
10
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Martin Meyerhoff
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,90 @@
1
+ # Physical
2
+
3
+ This is a small library to describe Packages (that could, potentially, be mailed).
4
+
5
+ A `Physical::Package` represents a package. It has and ID, dimensions, and a weight.
6
+
7
+ The `Package` takes it's dimensions from its `container` object, usually a `Physical::Box`.
8
+ It also has a `Set` of `Physical::Item`s that together make with the container make up everything
9
+ about the Package.
10
+
11
+ All things are thought to be cuboid: They have three dimensions, and a weight.
12
+
13
+ The weight of a `Package` is the weight of it's container plus the weight of all items, plus the weight
14
+ of any void fill.
15
+
16
+ By default, the `Physical::Box` is infinitely large. In order to limit the size of the Box, simply give it
17
+ dimensions.
18
+
19
+ ## Installation
20
+
21
+ Add this line to your application's Gemfile:
22
+
23
+ ```ruby
24
+ gem 'physical'
25
+ ```
26
+
27
+ And then execute:
28
+
29
+ $ bundle
30
+
31
+ Or install it yourself as:
32
+
33
+ $ gem install physical
34
+
35
+ ## Usage
36
+
37
+ ```ruby
38
+ one_sku = Physical::Item.new(
39
+ id: '12345',
40
+ dimensions: [2, 4, 5],
41
+ dimension_unit: :inch,
42
+ weight: 1,
43
+ weight_unit: :kg
44
+ )
45
+
46
+ two_sku = Physical::Item.new(
47
+ id: "54321",
48
+ dimensions: [1, 1, 1],
49
+ dimension_unit: :cm,
50
+ weight: 2.3,
51
+ weight_unit: :g
52
+ )
53
+
54
+ my_carton = Physical::Box.new(
55
+ dimensions: [10, 15, 15],
56
+ dimension_unit: :cm,
57
+ weight: 0.8,
58
+ weight_unit: :lbs
59
+ )
60
+
61
+ package = Physical::Package.new(
62
+ id: "my_package",
63
+ container: my_carton,
64
+ items: [one_sku, two_sku],
65
+ void_fill_density: 0.007
66
+ )
67
+
68
+ package.weight
69
+ => #<Measured::Weight: 1376.32851808 #<Measured::Unit: g (gram, grams)>>
70
+
71
+ package.remaining_volume
72
+ => #<Measured::Volume: 1593.51744 #<Measured::Unit: ml (milliliter, millilitre, milliliters, millilitres) 1/1000 l>>
73
+ ```
74
+ ## Development
75
+
76
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
77
+
78
+ 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).
79
+
80
+ ## Contributing
81
+
82
+ Bug reports and pull requests are welcome on GitHub at https://github.com/mamhoff/physical. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
83
+
84
+ ## License
85
+
86
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
87
+
88
+ ## Code of Conduct
89
+
90
+ Everyone interacting in the Physical project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/physical/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "physical"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'measured'
4
+
5
+ module Physical
6
+ class Box < Cuboid
7
+ DEFAULT_LENGTH = BigDecimal::INFINITY
8
+ end
9
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'measured'
4
+
5
+ module Physical
6
+ class Cuboid
7
+ attr_reader :dimensions, :weight, :id
8
+
9
+ def initialize(id: nil, dimensions: [], dimension_unit: :cm, weight: 0, weight_unit: :g)
10
+ @id = id || SecureRandom.uuid
11
+ @weight = Measured::Weight(weight, weight_unit).convert_to(:g)
12
+ @dimensions = dimensions.map { |dimension| Measured::Length.new(dimension, dimension_unit).convert_to(:cm) }
13
+ @dimensions.fill(Measured::Length(self.class::DEFAULT_LENGTH, dimension_unit), @dimensions.length..2)
14
+ end
15
+
16
+ def volume
17
+ Measured::Volume(dimensions.map(&:value).reduce(&:*), :ml)
18
+ end
19
+
20
+ def ==(other)
21
+ id == other.id
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Physical
4
+ class Item < Cuboid
5
+ DEFAULT_LENGTH = 0
6
+
7
+ attr_reader :properties
8
+
9
+ def initialize(properties: {}, **args)
10
+ @properties = properties
11
+ super(args)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,98 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'carmen'
4
+
5
+ module Physical
6
+ class Location
7
+ ADDRESS_TYPES = %w(residential commercial po_box)
8
+
9
+ attr_reader :country,
10
+ :zip,
11
+ :region,
12
+ :city,
13
+ :name,
14
+ :address1,
15
+ :address2,
16
+ :address3,
17
+ :phone,
18
+ :fax,
19
+ :email,
20
+ :address_type,
21
+ :company_name
22
+
23
+ def initialize(
24
+ name: nil,
25
+ company_name: nil,
26
+ address1: nil,
27
+ address2: nil,
28
+ address3: nil,
29
+ city: nil,
30
+ region: nil,
31
+ zip: nil,
32
+ country: nil,
33
+ phone: nil,
34
+ fax: nil,
35
+ email: nil,
36
+ address_type: nil
37
+ )
38
+
39
+ if country.is_a?(Carmen::Country)
40
+ @country = country
41
+ else
42
+ @country = Carmen::Country.coded(country.to_s)
43
+ end
44
+
45
+ if region.is_a?(Carmen::Region)
46
+ @region = region
47
+ elsif country.is_a?(Carmen::Country)
48
+ @region = country.subregions.coded(region.to_s.upcase)
49
+ end
50
+
51
+ @name = name
52
+ @company_name = company_name
53
+ @address1 = address1
54
+ @address2 = address2
55
+ @address3 = address3
56
+ @city = city
57
+ @zip = zip
58
+ @phone = phone
59
+ @fax = fax
60
+ @email = email
61
+ @address_type = address_type
62
+ end
63
+
64
+ def residential?
65
+ @address_type == 'residential'
66
+ end
67
+
68
+ def commercial?
69
+ @address_type == 'commercial'
70
+ end
71
+
72
+ def po_box?
73
+ @address_type == 'po_box'
74
+ end
75
+
76
+ def to_hash
77
+ {
78
+ country: country.code,
79
+ postal_code: zip,
80
+ province: province.code,
81
+ city: city,
82
+ name: name,
83
+ address1: address1,
84
+ address2: address2,
85
+ address3: address3,
86
+ phone: phone,
87
+ fax: fax,
88
+ email: email,
89
+ address_type: address_type,
90
+ company_name: company_name
91
+ }
92
+ end
93
+
94
+ def ==(other)
95
+ to_hash == other.to_hash
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Physical
4
+ class Package
5
+ attr_reader :container, :items, :void_fill_density, :id
6
+
7
+ def initialize(id: nil, container: Physical::Box.new, items: [], void_fill_density: 0, void_fill_density_unit: :g)
8
+ @id = id || SecureRandom.uuid
9
+ @void_fill_density = Measured::Weight(void_fill_density, void_fill_density_unit)
10
+ @container = container
11
+ @items = Set[*items]
12
+ end
13
+
14
+ def <<(item)
15
+ @items.add(item)
16
+ end
17
+
18
+ def >>(item)
19
+ @items.delete(item)
20
+ end
21
+
22
+ def weight
23
+ container.weight + items.map(&:weight).reduce(&:+) + void_fill_weight
24
+ end
25
+
26
+ def remaining_volume
27
+ container.volume - items.map(&:volume).reduce(&:+)
28
+ end
29
+
30
+ def void_fill_weight
31
+ return Measured::Weight(0, :g) if container.volume.value.infinite?
32
+
33
+ Measured::Weight(void_fill_density.value * remaining_volume.value, void_fill_density.unit)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Physical
4
+ class Shipment
5
+ attr_reader :id,
6
+ :origin,
7
+ :destination,
8
+ :shipping_method,
9
+ :packages,
10
+ :options
11
+
12
+ def initialize(id: nil, origin: nil, destination: nil, shipping_method: nil, packages: [], options: {})
13
+ @id = id || SecureRandom.uuid
14
+ @origin = origin
15
+ @destination = destination
16
+ @shipping_method = shipping_method
17
+ @packages = packages
18
+ @options = options
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'factory_bot'
4
+
5
+ FactoryBot.define do
6
+ factory :physical_box, class: "Physical::Box" do
7
+ dimensions { [4, 5, 6] }
8
+ dimension_unit { :dm }
9
+ weight { 0.1 }
10
+ weight_unit { :kg }
11
+ initialize_with { new(attributes) }
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'factory_bot'
4
+
5
+ FactoryBot.define do
6
+ factory :physical_item, class: "Physical::Item" do
7
+ dimensions { [1, 2, 3] }
8
+ dimension_unit { :cm }
9
+ weight { 50 }
10
+ weight_unit { :g }
11
+ initialize_with { new(attributes) }
12
+ end
13
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
4
+ factory :physical_location, class: 'Physical::Location' do
5
+ transient do
6
+ country_code { 'US' }
7
+ region_code { 'IL' }
8
+ end
9
+
10
+ name { 'Jane Doe' }
11
+ company_name { 'Company' }
12
+ address1 { '11 Lovely Street' }
13
+ address2 { 'South' }
14
+ city { 'Herndon' }
15
+ sequence(:zip, 10001) { |i| i.to_s }
16
+ phone { '555-555-0199' }
17
+ region { country.subregions.coded(region_code) }
18
+ country { Carmen::Country.coded(country_code) }
19
+ initialize_with { new(attributes) }
20
+ end
21
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'factory_bot'
4
+
5
+ FactoryBot.define do
6
+ factory :physical_package, class: "Physical::Package" do
7
+ container { FactoryBot.build(:physical_box) }
8
+ items { build_list(:physical_item, 2) }
9
+ void_fill_density { 0.01 }
10
+ initialize_with { new(attributes) }
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'factory_bot'
4
+
5
+ FactoryBot.define do
6
+ factory :physical_shipment, class: "Physical::Shipment" do
7
+ origin { FactoryBot.build(:physical_location) }
8
+ destination { FactoryBot.build(:physical_location) }
9
+ packages { build_list(:physical_package, 2) }
10
+ shipping_method { "USPS Priority" }
11
+ initialize_with { new(attributes) }
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'physical/spec_support/factories/item_factory'
4
+ require 'physical/spec_support/factories/box_factory'
5
+ require 'physical/spec_support/factories/package_factory'
6
+ require 'physical/spec_support/factories/location_factory'
7
+ require 'physical/spec_support/factories/shipment_factory'
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Physical
4
+ VERSION = "0.1.0"
5
+ end
data/lib/physical.rb ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "physical/version"
4
+ require "physical/cuboid"
5
+ require "physical/box"
6
+ require "physical/package"
7
+ require "physical/item"
8
+ require "physical/location"
9
+ require "physical/shipment"
10
+
11
+ module Physical
12
+ # Your code goes here...
13
+ end
data/physical.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "physical/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "physical"
9
+ spec.version = Physical::VERSION
10
+ spec.authors = ["Martin Meyerhoff"]
11
+ spec.email = ["mamhoff@gmail.com"]
12
+
13
+ spec.summary = "A facade to deal with physical packages"
14
+ spec.description = "A package with boxes and items"
15
+ spec.homepage = "https://github.com/mamhoff/physical"
16
+ spec.license = "MIT"
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
19
+ f.match(%r{^(spec)/})
20
+ end
21
+ spec.require_paths = ["lib"]
22
+ spec.required_ruby_version = '>= 2.4'
23
+ spec.add_runtime_dependency "carmen", "~> 1.0"
24
+ spec.add_runtime_dependency "factory_bot", "~> 4.8 "
25
+ spec.add_runtime_dependency "measured", "~> 2.4.0"
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.16"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "rspec", "~> 3.0"
30
+ end
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: physical
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Martin Meyerhoff
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-12-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: carmen
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: factory_bot
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '4.8'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '4.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: measured
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 2.4.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 2.4.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.16'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.16'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ description: A package with boxes and items
98
+ email:
99
+ - mamhoff@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".circleci/config.yml"
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".rubocop.yml"
108
+ - ".ruby-version"
109
+ - ".travis.yml"
110
+ - CODE_OF_CONDUCT.md
111
+ - Gemfile
112
+ - LICENSE.txt
113
+ - README.md
114
+ - Rakefile
115
+ - bin/console
116
+ - bin/setup
117
+ - lib/physical.rb
118
+ - lib/physical/box.rb
119
+ - lib/physical/cuboid.rb
120
+ - lib/physical/item.rb
121
+ - lib/physical/location.rb
122
+ - lib/physical/package.rb
123
+ - lib/physical/shipment.rb
124
+ - lib/physical/spec_support/factories.rb
125
+ - lib/physical/spec_support/factories/box_factory.rb
126
+ - lib/physical/spec_support/factories/item_factory.rb
127
+ - lib/physical/spec_support/factories/location_factory.rb
128
+ - lib/physical/spec_support/factories/package_factory.rb
129
+ - lib/physical/spec_support/factories/shipment_factory.rb
130
+ - lib/physical/version.rb
131
+ - physical.gemspec
132
+ homepage: https://github.com/mamhoff/physical
133
+ licenses:
134
+ - MIT
135
+ metadata: {}
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '2.4'
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubyforge_project:
152
+ rubygems_version: 2.6.14.1
153
+ signing_key:
154
+ specification_version: 4
155
+ summary: A facade to deal with physical packages
156
+ test_files: []