boxbot 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.travis.yml +17 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +124 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +34 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/boxbot.gemspec +39 -0
- data/lib/boxbot.rb +20 -0
- data/lib/boxbot/compute/tab_calculator.rb +104 -0
- data/lib/boxbot/dimensions.rb +71 -0
- data/lib/boxbot/edge.rb +28 -0
- data/lib/boxbot/types.rb +31 -0
- data/lib/boxbot/version.rb +3 -0
- metadata +257 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9a637cc4c6c5fe2f4350331e0e1b3d57ca9d5f16283ffaf36848180010d79496
|
4
|
+
data.tar.gz: aac8f54a6c7b8e14d2e9cfcc3ed82d57fad42556b4809404a223ce7de13b3fb9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9855b84986a678cf9a22e5f7ce5a1a06cbca94a6d3acaf1d07730b359adad7797e10b67fd36482f5ed1215e433d1e5aa1af0fe47c74a20fa1c7c00d1bbdd865d
|
7
|
+
data.tar.gz: f67e9dbb4c301523efd2051b79f7eee3bf551602d7d23498a62cef29668792ac9be62817bcacf151f6475eb4b203cac1f884c4bff1f148c4bb8d2b6ae783b128
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
sudo: false
|
2
|
+
cache: bundler
|
3
|
+
language: ruby
|
4
|
+
rvm:
|
5
|
+
- 2.5.0
|
6
|
+
before_install: gem install bundler -v 1.16.1
|
7
|
+
before_script:
|
8
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
9
|
+
- chmod +x ./cc-test-reporter
|
10
|
+
- ./cc-test-reporter before-build
|
11
|
+
script:
|
12
|
+
- bundle exec rspec
|
13
|
+
after_script:
|
14
|
+
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
15
|
+
env:
|
16
|
+
global:
|
17
|
+
secure: sgWVRNObYXP7vqAZSAgVON1K5wyrLOH+K3hDqd8Wr1oec5d7FO8JpKniVqmdyVNkOBhn4gRF4lYaNZqOtXh20VmuQvLBBPKzX4bGIwRbayNi3ctU1C/srQWWOnBei0aCpaiXU6ajfTTSBtb4HdHqWyZqHkoMpfAKR8oGT+QhPFIKqLvyf0Hbitg66s4qW0f0mDFIvDsSG2YKV7JxdY9bPw6+iY9f+vOJhmqRf7D6zKmmV0rPMg5cRfJirCEYd2CcusxaX+X7xCy8apdezQrZYwwMZrzma8eqFQvRhk6gX2Bn2XnYxtw2PVRrWLPeIRJ/lUEWZbz+wXwCrTy0KDGVu9ZwNmLiylpuPqKLh7i44Ia5ccHROPj1FueyAqH1/TL6BpkFutpy32LfPGgLD14gHmEN3W+1HZ56NibSeQdHvCNCx+IOLoJXxvnrBkOaQEw8gYPQPN9d/PoXHhe7ocRkX3aDpJ4PW0Zcy+b6hJj/588yq8BlEdYRZFsyDeiZCnwqYF1tUhGHKHYU4Pfq3+GzXfEKkIGR77rP0uMtITfy/LgrAv57dN7gDEHhVe3ozSDav5kp4b84qMSt2Ndm4FIByfChHqYh7mMl8rziCDtvwVoNmcCICjLvOFXdyh1Ae9myqey6+Yar+qFC8qL3fYLTvcWZDljPOJOqPkB2Muo9qn8=
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
boxbot (0.1.0)
|
5
|
+
dry-configurable
|
6
|
+
dry-monads
|
7
|
+
dry-struct
|
8
|
+
dry-types
|
9
|
+
hashie
|
10
|
+
require_dir
|
11
|
+
victor
|
12
|
+
|
13
|
+
GEM
|
14
|
+
remote: https://rubygems.org/
|
15
|
+
specs:
|
16
|
+
aruba (0.14.3)
|
17
|
+
childprocess (~> 0.8.0)
|
18
|
+
contracts (~> 0.9)
|
19
|
+
cucumber (>= 1.3.19)
|
20
|
+
ffi (~> 1.9.10)
|
21
|
+
rspec-expectations (>= 2.99)
|
22
|
+
thor (~> 0.19)
|
23
|
+
backports (3.11.1)
|
24
|
+
builder (3.2.3)
|
25
|
+
childprocess (0.8.0)
|
26
|
+
ffi (~> 1.0, >= 1.0.11)
|
27
|
+
concurrent-ruby (1.0.5)
|
28
|
+
contracts (0.16.0)
|
29
|
+
cucumber (3.1.0)
|
30
|
+
builder (>= 2.1.2)
|
31
|
+
cucumber-core (~> 3.1.0)
|
32
|
+
cucumber-expressions (~> 5.0.4)
|
33
|
+
cucumber-wire (~> 0.0.1)
|
34
|
+
diff-lcs (~> 1.3)
|
35
|
+
gherkin (~> 5.0)
|
36
|
+
multi_json (>= 1.7.5, < 2.0)
|
37
|
+
multi_test (>= 0.1.2)
|
38
|
+
cucumber-core (3.1.0)
|
39
|
+
backports (>= 3.8.0)
|
40
|
+
cucumber-tag_expressions (~> 1.1.0)
|
41
|
+
gherkin (>= 5.0.0)
|
42
|
+
cucumber-expressions (5.0.13)
|
43
|
+
cucumber-tag_expressions (1.1.1)
|
44
|
+
cucumber-wire (0.0.1)
|
45
|
+
diff-lcs (1.3)
|
46
|
+
docile (1.1.5)
|
47
|
+
dry-configurable (0.7.0)
|
48
|
+
concurrent-ruby (~> 1.0)
|
49
|
+
dry-container (0.6.0)
|
50
|
+
concurrent-ruby (~> 1.0)
|
51
|
+
dry-configurable (~> 0.1, >= 0.1.3)
|
52
|
+
dry-core (0.4.4)
|
53
|
+
concurrent-ruby (~> 1.0)
|
54
|
+
dry-equalizer (0.2.0)
|
55
|
+
dry-logic (0.4.2)
|
56
|
+
dry-container (~> 0.2, >= 0.2.6)
|
57
|
+
dry-core (~> 0.2)
|
58
|
+
dry-equalizer (~> 0.2)
|
59
|
+
dry-monads (0.4.0)
|
60
|
+
dry-core (~> 0.3, >= 0.3.3)
|
61
|
+
dry-equalizer
|
62
|
+
dry-struct (0.4.0)
|
63
|
+
dry-core (~> 0.4, >= 0.4.1)
|
64
|
+
dry-equalizer (~> 0.2)
|
65
|
+
dry-types (~> 0.12, >= 0.12.2)
|
66
|
+
ice_nine (~> 0.11)
|
67
|
+
dry-types (0.12.2)
|
68
|
+
concurrent-ruby (~> 1.0)
|
69
|
+
dry-configurable (~> 0.1)
|
70
|
+
dry-container (~> 0.3)
|
71
|
+
dry-core (~> 0.2, >= 0.2.1)
|
72
|
+
dry-equalizer (~> 0.2)
|
73
|
+
dry-logic (~> 0.4, >= 0.4.2)
|
74
|
+
inflecto (~> 0.0.0, >= 0.0.2)
|
75
|
+
ffi (1.9.22)
|
76
|
+
gherkin (5.0.0)
|
77
|
+
hashie (3.5.7)
|
78
|
+
ice_nine (0.11.2)
|
79
|
+
inflecto (0.0.2)
|
80
|
+
json (2.1.0)
|
81
|
+
multi_json (1.13.1)
|
82
|
+
multi_test (0.1.2)
|
83
|
+
rake (10.5.0)
|
84
|
+
require_dir (0.1.2)
|
85
|
+
rspec (3.7.0)
|
86
|
+
rspec-core (~> 3.7.0)
|
87
|
+
rspec-expectations (~> 3.7.0)
|
88
|
+
rspec-mocks (~> 3.7.0)
|
89
|
+
rspec-core (3.7.1)
|
90
|
+
rspec-support (~> 3.7.0)
|
91
|
+
rspec-expectations (3.7.0)
|
92
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
93
|
+
rspec-support (~> 3.7.0)
|
94
|
+
rspec-its (1.2.0)
|
95
|
+
rspec-core (>= 3.0.0)
|
96
|
+
rspec-expectations (>= 3.0.0)
|
97
|
+
rspec-mocks (3.7.0)
|
98
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
99
|
+
rspec-support (~> 3.7.0)
|
100
|
+
rspec-support (3.7.1)
|
101
|
+
simplecov (0.15.1)
|
102
|
+
docile (~> 1.1.0)
|
103
|
+
json (>= 1.8, < 3)
|
104
|
+
simplecov-html (~> 0.10.0)
|
105
|
+
simplecov-html (0.10.2)
|
106
|
+
thor (0.20.0)
|
107
|
+
victor (0.2.1)
|
108
|
+
yard (0.9.12)
|
109
|
+
|
110
|
+
PLATFORMS
|
111
|
+
ruby
|
112
|
+
|
113
|
+
DEPENDENCIES
|
114
|
+
aruba
|
115
|
+
boxbot!
|
116
|
+
bundler (~> 1.15)
|
117
|
+
rake (~> 10.0)
|
118
|
+
rspec (~> 3.0)
|
119
|
+
rspec-its
|
120
|
+
simplecov
|
121
|
+
yard
|
122
|
+
|
123
|
+
BUNDLED WITH
|
124
|
+
1.16.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Konstantin Gredeskoul
|
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,43 @@
|
|
1
|
+
[](https://travis-ci.org/kigster/boxbot)
|
2
|
+
[](https://codeclimate.com/github/kigster/boxbot/maintainability)
|
3
|
+
[](https://codeclimate.com/github/kigster/boxbot/test_coverage)
|
4
|
+
|
5
|
+
# Boxbot
|
6
|
+
|
7
|
+
**Work In Progress**
|
8
|
+
|
9
|
+
This is a rewrite of the [laser-cutter](https://github.com/kigster/laser-cutter) box drawing logic.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'boxbot'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
$ gem install boxbot
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
Soon.
|
30
|
+
|
31
|
+
## Development
|
32
|
+
|
33
|
+
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.
|
34
|
+
|
35
|
+
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).
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/kigster/boxbot.
|
40
|
+
|
41
|
+
## License
|
42
|
+
|
43
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
require 'yard'
|
4
|
+
|
5
|
+
def shell(*args)
|
6
|
+
puts "running: #{args.join(' ')}"
|
7
|
+
system(args.join(' '))
|
8
|
+
end
|
9
|
+
|
10
|
+
task :clean do
|
11
|
+
shell('rm -rf pkg/ tmp/ coverage/ doc/ spec/fixtures/')
|
12
|
+
end
|
13
|
+
|
14
|
+
task :gem => [:build] do
|
15
|
+
shell('gem install pkg/*')
|
16
|
+
end
|
17
|
+
|
18
|
+
task :permissions => [ :clean ] do
|
19
|
+
shell("chmod -v o+r,g+r * */* */*/* */*/*/* */*/*/*/* */*/*/*/*/*")
|
20
|
+
shell("find . -type d -exec chmod o+x,g+x {} \\;")
|
21
|
+
end
|
22
|
+
|
23
|
+
task :build => :permissions
|
24
|
+
|
25
|
+
YARD::Rake::YardocTask.new(:doc) do |t|
|
26
|
+
t.files = %w(lib/**/*.rb exe/*.rb - README.md LICENSE.txt)
|
27
|
+
t.options.unshift('--title','BoxBot')
|
28
|
+
t.after = ->() { exec('open doc/index.html') }
|
29
|
+
end
|
30
|
+
|
31
|
+
RSpec::Core::RakeTask.new(:spec)
|
32
|
+
|
33
|
+
task :default => :spec
|
34
|
+
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "boxbot"
|
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
data/boxbot.gemspec
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'boxbot/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'boxbot'
|
8
|
+
spec.version = Boxbot::VERSION
|
9
|
+
spec.authors = ['Konstantin Gredeskoul']
|
10
|
+
spec.email = ['kigster@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = 'Boxbot - is a work in progress replacement of the laser-cutter ruby gem'
|
13
|
+
spec.description = 'Boxbot - is a work in progress replacement of the laser-cutter ruby gem'
|
14
|
+
spec.homepage = 'https://github.com/kigster/boxbot'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = 'exe'
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ['lib']
|
23
|
+
|
24
|
+
spec.add_dependency 'dry-configurable'
|
25
|
+
spec.add_dependency 'dry-monads'
|
26
|
+
spec.add_dependency 'dry-struct'
|
27
|
+
spec.add_dependency 'dry-types'
|
28
|
+
spec.add_dependency 'hashie'
|
29
|
+
spec.add_dependency 'require_dir'
|
30
|
+
spec.add_dependency 'victor'
|
31
|
+
|
32
|
+
spec.add_development_dependency 'aruba'
|
33
|
+
spec.add_development_dependency 'bundler', '~> 1.15'
|
34
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
35
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
36
|
+
spec.add_development_dependency 'rspec-its'
|
37
|
+
spec.add_development_dependency 'simplecov'
|
38
|
+
spec.add_development_dependency 'yard'
|
39
|
+
end
|
data/lib/boxbot.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'boxbot/version'
|
2
|
+
require 'dry-types'
|
3
|
+
|
4
|
+
Dry::Types.load_extensions(:maybe)
|
5
|
+
|
6
|
+
require 'boxbot/types'
|
7
|
+
require 'boxbot/dimensions'
|
8
|
+
require 'boxbot/edge'
|
9
|
+
require 'boxbot/compute/tab_calculator'
|
10
|
+
|
11
|
+
# Main namespace for the Boxbot library.
|
12
|
+
#
|
13
|
+
# The library aims to create a way to generate laser-cutter cut templates
|
14
|
+
# as easily as possible, while keeping the sides symmetric.
|
15
|
+
#
|
16
|
+
# @see https://github.com/kigster/boxbot
|
17
|
+
# @author Konstantin Gredeskoul
|
18
|
+
module Boxbot
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'dry-struct'
|
2
|
+
require 'dry-types'
|
3
|
+
require 'boxbot/types'
|
4
|
+
|
5
|
+
module Boxbot
|
6
|
+
module Compute
|
7
|
+
|
8
|
+
# Holds the result of Tab Width Computation.
|
9
|
+
#
|
10
|
+
# @attr [String] dimension name
|
11
|
+
# @attr [Float] length the length of the dimension
|
12
|
+
# @attr [Integer] tab_count the total number of tabs along this dimension
|
13
|
+
# @attr [Float] tab_width length of each tab without the kerf adjustment
|
14
|
+
#
|
15
|
+
TabWidthResult = Struct.new(:dimension, :length, :tab_count, :tab_width)
|
16
|
+
|
17
|
+
MAX_TAB_COUNT = (ENV['BOXBOT__MAX_TAB_COUNT'] || '99').to_i
|
18
|
+
|
19
|
+
# Computes the actual tab with for a given dimension index or name.
|
20
|
+
#
|
21
|
+
# @author Konstantin Gredeskoul
|
22
|
+
# @attr [Boxbot::Dimensions] dimensions instance
|
23
|
+
#
|
24
|
+
# @example compute number of tabs for the vertical dimension
|
25
|
+
# dim = Boxbot::Dimension.new(width: 10, ... )
|
26
|
+
# Boxbot::Compute::TabCalculator.new(dim)['height']
|
27
|
+
# # => 9
|
28
|
+
#
|
29
|
+
class TabCalculator
|
30
|
+
attr_accessor :dimensions
|
31
|
+
|
32
|
+
def initialize(dimensions)
|
33
|
+
self.dimensions = dimensions
|
34
|
+
end
|
35
|
+
|
36
|
+
# Computes the tab width for a given dimension, and returns
|
37
|
+
# a TabWithResult struct.
|
38
|
+
#
|
39
|
+
# @param dimension_identifier [Symbol,String,Integer] A name, symbol
|
40
|
+
# or an integer index of one of 3 dimensions.
|
41
|
+
# Can be 'width' or 0, 'height' or 1, 'depth' or 2
|
42
|
+
#
|
43
|
+
# @return [TabWidthResult] struct with tab width, count and length
|
44
|
+
# @raise ArgumentError if argument is not a String, Symbol, or Integer.
|
45
|
+
def calculate(dimension_identifier)
|
46
|
+
index = resolve_dimension_argument(dimension_identifier)
|
47
|
+
length = dimensions.inner_box[index]
|
48
|
+
tab_count = tab_count_for_length(length)
|
49
|
+
tab_width = length / tab_count
|
50
|
+
|
51
|
+
TabWidthResult.new(Types::Dimensions[index],
|
52
|
+
length,
|
53
|
+
tab_count,
|
54
|
+
tab_width)
|
55
|
+
end
|
56
|
+
|
57
|
+
# Computes the tab count for a given dimension, and returns
|
58
|
+
# an integer result.
|
59
|
+
#
|
60
|
+
# @param (see #calculate)
|
61
|
+
# @return [Integer] Number of tabs along this dimension
|
62
|
+
# @raise ArgumentError if argument is not a String, Symbol, or Integer.
|
63
|
+
def [](dimension_identifier)
|
64
|
+
tab_count_for_length(
|
65
|
+
dimension_length(
|
66
|
+
dimension_identifier
|
67
|
+
)
|
68
|
+
)
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
|
73
|
+
def dimension_length(dimension_identifier)
|
74
|
+
index = resolve_dimension_argument(dimension_identifier)
|
75
|
+
dimensions.inner_box[index]
|
76
|
+
end
|
77
|
+
|
78
|
+
def tab_count_for_length(length)
|
79
|
+
return nil unless length
|
80
|
+
tab_count = (length / dimensions.tab_width).to_i
|
81
|
+
if tab_count > MAX_TAB_COUNT
|
82
|
+
MAX_TAB_COUNT
|
83
|
+
elsif tab_count < 3
|
84
|
+
3
|
85
|
+
elsif tab_count.even?
|
86
|
+
tab_count + 1
|
87
|
+
else
|
88
|
+
tab_count
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def resolve_dimension_argument(dimension_identifier)
|
93
|
+
case dimension_identifier
|
94
|
+
when Numeric
|
95
|
+
dimension_identifier
|
96
|
+
when String, Symbol
|
97
|
+
Boxbot::Edge.dimension_index(dimension_identifier.to_s)
|
98
|
+
else
|
99
|
+
raise ArgumentError, "invalid argument type #{dimension_identifier.class}"
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'dry-struct'
|
2
|
+
require 'dry-types'
|
3
|
+
require 'boxbot/types'
|
4
|
+
|
5
|
+
module Boxbot
|
6
|
+
|
7
|
+
# Holds the internal dimensions of the box, including
|
8
|
+
# laser-specific parameters such as kerf and material thickness.
|
9
|
+
#
|
10
|
+
# @author Konstantin Gredeskoul
|
11
|
+
#
|
12
|
+
# @attr [Float] width
|
13
|
+
# @attr [Float] height
|
14
|
+
# @attr [Float] depth
|
15
|
+
# @attr [Float] kerf
|
16
|
+
# @attr [Float] thickness
|
17
|
+
# @attr [Float] tab desired tab width/length used as a guide
|
18
|
+
#
|
19
|
+
# @example compute number of tabs for the vertical dimension
|
20
|
+
# dim = Boxbot::Dimension.new(width: 10, height: 2, depth: 3, ...)
|
21
|
+
# dim.inner_box # => [ 10, 2, 3 ]
|
22
|
+
#
|
23
|
+
class Dimensions < Dry::Struct
|
24
|
+
constructor_type :schema
|
25
|
+
|
26
|
+
attribute :width, Types::Strict::Float
|
27
|
+
attribute :height, Types::Strict::Float
|
28
|
+
attribute :depth, Types::Strict::Float
|
29
|
+
attribute :kerf, Types::Strict::Float
|
30
|
+
attribute :thickness, Types::Strict::Float
|
31
|
+
attribute :tab, Types::Strict::Float.optional
|
32
|
+
|
33
|
+
def initialize(*args, &block)
|
34
|
+
super(*args, &block)
|
35
|
+
self.kerf ||= 0
|
36
|
+
end
|
37
|
+
|
38
|
+
# Returns dimensions of the inner box.
|
39
|
+
# @return [Array<Integer>] three dimensional array of width, height, depth
|
40
|
+
def inner_box
|
41
|
+
[width, height, depth]
|
42
|
+
end
|
43
|
+
|
44
|
+
# Returns dimensions of the outer box by adding thickness to the inner box.
|
45
|
+
# @return [Array<Integer>] three dimensional array of width, height, depth
|
46
|
+
def outer_box
|
47
|
+
inner_box.map { |d| o(d) }
|
48
|
+
end
|
49
|
+
|
50
|
+
# Returns dimensions of the outer box with kerf added.
|
51
|
+
# @return [Array<Integer>] three dimensional array of width, height, depth
|
52
|
+
def outer_box_with_kerf
|
53
|
+
inner_box.map { |d| o(d, add_kerf: true) }
|
54
|
+
end
|
55
|
+
|
56
|
+
# Returns either provided or the default tab width.
|
57
|
+
# The default is computed as `4 x thickness.`
|
58
|
+
# @return [Float] tab width
|
59
|
+
def tab_width
|
60
|
+
raise ArgumentError, 'Thickness is zero?' if thickness.zero?
|
61
|
+
tab ? tab : thickness * 4
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def o(attr, add_kerf: false)
|
67
|
+
attr + 2 * thickness + (add_kerf ? 2 * kerf : 0)
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
data/lib/boxbot/edge.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'dry-struct'
|
2
|
+
require 'dry-types'
|
3
|
+
require 'boxbot'
|
4
|
+
module Boxbot
|
5
|
+
class Edge < Dry::Struct
|
6
|
+
constructor_type :schema
|
7
|
+
|
8
|
+
attribute :face, Types::BoxFaces
|
9
|
+
attribute :joins, Types::BoxFaces
|
10
|
+
attribute :dimension, Types::Dimensions
|
11
|
+
attribute :dimensions, Dimensions
|
12
|
+
attribute :direction, Types::EdgeDirection
|
13
|
+
|
14
|
+
def initialize(*args, &block)
|
15
|
+
super(*args, &block)
|
16
|
+
end
|
17
|
+
|
18
|
+
def dimension_index
|
19
|
+
self.class.dimension_index(dimension)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.dimension_index(dim)
|
23
|
+
Types::Dimensions.values.find_index(dim)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
data/lib/boxbot/types.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'dry-types'
|
2
|
+
require 'dry-struct'
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
module Boxbot
|
6
|
+
module Types
|
7
|
+
|
8
|
+
include ::Dry::Types.module
|
9
|
+
|
10
|
+
BoxFaces = String.enum *%w[
|
11
|
+
top
|
12
|
+
bottom
|
13
|
+
left
|
14
|
+
right
|
15
|
+
front
|
16
|
+
back
|
17
|
+
]
|
18
|
+
|
19
|
+
EdgeDirection = String.enum *%w[
|
20
|
+
out
|
21
|
+
in
|
22
|
+
]
|
23
|
+
|
24
|
+
Dimensions = String.enum *%w[
|
25
|
+
width
|
26
|
+
height
|
27
|
+
depth
|
28
|
+
]
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,257 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: boxbot
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Konstantin Gredeskoul
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-02-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: dry-configurable
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: dry-monads
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: dry-struct
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: dry-types
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: hashie
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: require_dir
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: victor
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: aruba
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: bundler
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '1.15'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '1.15'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rake
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '10.0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '10.0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: rspec
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '3.0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '3.0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: rspec-its
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: simplecov
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - ">="
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: yard
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - ">="
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '0'
|
202
|
+
type: :development
|
203
|
+
prerelease: false
|
204
|
+
version_requirements: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - ">="
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: '0'
|
209
|
+
description: Boxbot - is a work in progress replacement of the laser-cutter ruby gem
|
210
|
+
email:
|
211
|
+
- kigster@gmail.com
|
212
|
+
executables: []
|
213
|
+
extensions: []
|
214
|
+
extra_rdoc_files: []
|
215
|
+
files:
|
216
|
+
- ".gitignore"
|
217
|
+
- ".rspec"
|
218
|
+
- ".travis.yml"
|
219
|
+
- Gemfile
|
220
|
+
- Gemfile.lock
|
221
|
+
- LICENSE.txt
|
222
|
+
- README.md
|
223
|
+
- Rakefile
|
224
|
+
- bin/console
|
225
|
+
- bin/setup
|
226
|
+
- boxbot.gemspec
|
227
|
+
- lib/boxbot.rb
|
228
|
+
- lib/boxbot/compute/tab_calculator.rb
|
229
|
+
- lib/boxbot/dimensions.rb
|
230
|
+
- lib/boxbot/edge.rb
|
231
|
+
- lib/boxbot/types.rb
|
232
|
+
- lib/boxbot/version.rb
|
233
|
+
homepage: https://github.com/kigster/boxbot
|
234
|
+
licenses:
|
235
|
+
- MIT
|
236
|
+
metadata: {}
|
237
|
+
post_install_message:
|
238
|
+
rdoc_options: []
|
239
|
+
require_paths:
|
240
|
+
- lib
|
241
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
242
|
+
requirements:
|
243
|
+
- - ">="
|
244
|
+
- !ruby/object:Gem::Version
|
245
|
+
version: '0'
|
246
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
247
|
+
requirements:
|
248
|
+
- - ">="
|
249
|
+
- !ruby/object:Gem::Version
|
250
|
+
version: '0'
|
251
|
+
requirements: []
|
252
|
+
rubyforge_project:
|
253
|
+
rubygems_version: 2.7.3
|
254
|
+
signing_key:
|
255
|
+
specification_version: 4
|
256
|
+
summary: Boxbot - is a work in progress replacement of the laser-cutter ruby gem
|
257
|
+
test_files: []
|