slice_rename 0.3.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 +7 -0
- data/.rspec +3 -0
- data/.ruby-version +1 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +77 -0
- data/Guardfile +42 -0
- data/MIT-LICENSE +20 -0
- data/README.md +37 -0
- data/Rakefile +27 -0
- data/bin/guard +17 -0
- data/bin/rspec +17 -0
- data/bin/slice_rename +4 -0
- data/lib/slice_rename/cli.rb +52 -0
- data/lib/slice_rename/config.rb +44 -0
- data/lib/slice_rename/slicer.rb +47 -0
- data/lib/slice_rename.rb +5 -0
- data/slice_rename.gemspec +19 -0
- data/spec/fixtures/animals.png +0 -0
- data/spec/fixtures/config_example.yml +13 -0
- data/spec/slice_rename/config_spec.rb +64 -0
- data/spec/slice_rename/sanity_spec.rb +5 -0
- data/spec/slice_rename/slicer_spec.rb +38 -0
- data/spec/spec_helper.rb +96 -0
- metadata +66 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d9ccdfae67abd4149444be16e8d5ab35f8c34ff2
|
4
|
+
data.tar.gz: 09649ed5652c83d1b4554bc39565574daae3d2eb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0e62eda7b7534ac40c6ec42099c947c262fa299730eb78b4dd294de4f85ea7f6bedd2c5f39c7065c8537ff2507c5aaea5fae0faded4ab5f74fd7fe8c18a2a8bf
|
7
|
+
data.tar.gz: 1bdafecf17d09c8a739fab7d9aeff36bd6e3b73fe203483305771f521d5ec8d863bb16bfe194c88778f5d53be172330bae6fb6857ed7ddfcf7e4d9199c9e8ede
|
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.3.1
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
slice_rename (0.2.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
coderay (1.1.1)
|
10
|
+
diff-lcs (1.2.5)
|
11
|
+
ffi (1.9.10)
|
12
|
+
formatador (0.2.5)
|
13
|
+
guard (2.14.0)
|
14
|
+
formatador (>= 0.2.4)
|
15
|
+
listen (>= 2.7, < 4.0)
|
16
|
+
lumberjack (~> 1.0)
|
17
|
+
nenv (~> 0.1)
|
18
|
+
notiffany (~> 0.0)
|
19
|
+
pry (>= 0.9.12)
|
20
|
+
shellany (~> 0.0)
|
21
|
+
thor (>= 0.18.1)
|
22
|
+
guard-compat (1.2.1)
|
23
|
+
guard-rspec (4.7.0)
|
24
|
+
guard (~> 2.1)
|
25
|
+
guard-compat (~> 1.1)
|
26
|
+
rspec (>= 2.99.0, < 4.0)
|
27
|
+
listen (3.1.5)
|
28
|
+
rb-fsevent (~> 0.9, >= 0.9.4)
|
29
|
+
rb-inotify (~> 0.9, >= 0.9.7)
|
30
|
+
ruby_dep (~> 1.2)
|
31
|
+
lumberjack (1.0.10)
|
32
|
+
method_source (0.8.2)
|
33
|
+
mini_magick (4.5.1)
|
34
|
+
nenv (0.3.0)
|
35
|
+
notiffany (0.1.0)
|
36
|
+
nenv (~> 0.1)
|
37
|
+
shellany (~> 0.0)
|
38
|
+
pry (0.10.3)
|
39
|
+
coderay (~> 1.1.0)
|
40
|
+
method_source (~> 0.8.1)
|
41
|
+
slop (~> 3.4)
|
42
|
+
rb-fsevent (0.9.7)
|
43
|
+
rb-inotify (0.9.7)
|
44
|
+
ffi (>= 0.5.0)
|
45
|
+
rspec (3.4.0)
|
46
|
+
rspec-core (~> 3.4.0)
|
47
|
+
rspec-expectations (~> 3.4.0)
|
48
|
+
rspec-mocks (~> 3.4.0)
|
49
|
+
rspec-core (3.4.4)
|
50
|
+
rspec-support (~> 3.4.0)
|
51
|
+
rspec-expectations (3.4.0)
|
52
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
53
|
+
rspec-support (~> 3.4.0)
|
54
|
+
rspec-mocks (3.4.1)
|
55
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
56
|
+
rspec-support (~> 3.4.0)
|
57
|
+
rspec-support (3.4.1)
|
58
|
+
ruby_dep (1.3.1)
|
59
|
+
shellany (0.0.1)
|
60
|
+
slop (3.6.0)
|
61
|
+
thor (0.19.1)
|
62
|
+
|
63
|
+
PLATFORMS
|
64
|
+
ruby
|
65
|
+
|
66
|
+
DEPENDENCIES
|
67
|
+
guard
|
68
|
+
guard-rspec
|
69
|
+
mini_magick
|
70
|
+
rspec
|
71
|
+
slice_rename!
|
72
|
+
|
73
|
+
RUBY VERSION
|
74
|
+
ruby 2.3.1p112
|
75
|
+
|
76
|
+
BUNDLED WITH
|
77
|
+
1.12.4
|
data/Guardfile
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
## Uncomment and set this to only include directories you want to watch
|
5
|
+
# directories %w(app lib config test spec features) \
|
6
|
+
# .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
|
7
|
+
|
8
|
+
## Note: if you are using the `directories` clause above and you are not
|
9
|
+
## watching the project directory ('.'), then you will want to move
|
10
|
+
## the Guardfile to a watched dir and symlink it back, e.g.
|
11
|
+
#
|
12
|
+
# $ mkdir config
|
13
|
+
# $ mv Guardfile config/
|
14
|
+
# $ ln -s config/Guardfile .
|
15
|
+
#
|
16
|
+
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
|
17
|
+
|
18
|
+
# Note: The cmd option is now required due to the increasing number of ways
|
19
|
+
# rspec may be run, below are examples of the most common uses.
|
20
|
+
# * bundler: 'bundle exec rspec'
|
21
|
+
# * bundler binstubs: 'bin/rspec'
|
22
|
+
# * spring: 'bin/rspec' (This will use spring if running and you have
|
23
|
+
# installed the spring binstubs per the docs)
|
24
|
+
# * zeus: 'zeus rspec' (requires the server to be started separately)
|
25
|
+
# * 'just' rspec: 'rspec'
|
26
|
+
|
27
|
+
guard :rspec, cmd: "bundle exec rspec" do
|
28
|
+
require "guard/rspec/dsl"
|
29
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
30
|
+
|
31
|
+
# Feel free to open issues for suggestions and improvements
|
32
|
+
|
33
|
+
# RSpec files
|
34
|
+
rspec = dsl.rspec
|
35
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
36
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
37
|
+
watch(rspec.spec_files)
|
38
|
+
|
39
|
+
# Ruby files
|
40
|
+
ruby = dsl.ruby
|
41
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
42
|
+
end
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2016 Zoee Silcock mrzoee@gmail.com
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# Slice Rename
|
2
|
+
Slice an image and give each slice a specific name.
|
3
|
+
|
4
|
+
# Usage
|
5
|
+
The CLI takes two arguments, the path to the image to be sliced and a
|
6
|
+
configuration file. The output will be placed in the same folder as the input
|
7
|
+
image. If you don't provide a configuration file it will use default settings
|
8
|
+
which aren't useful for anything.
|
9
|
+
|
10
|
+
```
|
11
|
+
-c, --config MANDATORY Configuration file (see below)
|
12
|
+
-d, --debug Output debug info
|
13
|
+
-v, --version Display the version
|
14
|
+
-h, --help Display this message
|
15
|
+
```
|
16
|
+
|
17
|
+
## Configuration
|
18
|
+
See the example which is located at `spec/fixtures/config_example.yml`. The
|
19
|
+
suffixes aren't mandatory, if you skip them or don't provide enough it will use
|
20
|
+
an auto generated suffix instead (`_00`).
|
21
|
+
|
22
|
+
The sample image is part of a duty free asset pack from
|
23
|
+
[kenney.nl](http://kenney.nl/).
|
24
|
+
|
25
|
+
# About Rocket Pants
|
26
|
+

|
27
|
+
|
28
|
+
Rocket Pants is a small indie game studio based in Stockholm. If you like this
|
29
|
+
tool please consider supporting us by checking out our games. Find out more at
|
30
|
+
[rocketpants.se](http://rocketpants.se).
|
31
|
+
|
32
|
+
# Contributing
|
33
|
+
1. Fork it
|
34
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
35
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
36
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
37
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
task default: %w[run]
|
2
|
+
|
3
|
+
task :run do
|
4
|
+
ruby '-I ./lib bin/slice_rename spec/fixtures/animals.png -c spec/fixtures/config_example.yml'
|
5
|
+
end
|
6
|
+
|
7
|
+
namespace :run do
|
8
|
+
task :debug do
|
9
|
+
ruby '-I ./lib bin/slice_rename --debug spec/fixtures/animals.png -c spec/fixtures/config_example.yml'
|
10
|
+
end
|
11
|
+
|
12
|
+
task :version do
|
13
|
+
ruby '-I ./lib bin/slice_rename --version'
|
14
|
+
end
|
15
|
+
|
16
|
+
task :help do
|
17
|
+
ruby '-I ./lib bin/slice_rename --help'
|
18
|
+
end
|
19
|
+
|
20
|
+
task :invalid do
|
21
|
+
ruby '-I ./lib bin/slice_rename --poop'
|
22
|
+
end
|
23
|
+
|
24
|
+
task :missing do
|
25
|
+
ruby '-I ./lib bin/slice_rename'
|
26
|
+
end
|
27
|
+
end
|
data/bin/guard
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
#
|
4
|
+
# This file was generated by Bundler.
|
5
|
+
#
|
6
|
+
# The application 'guard' is installed as part of a gem, and
|
7
|
+
# this file is here to facilitate running it.
|
8
|
+
#
|
9
|
+
|
10
|
+
require "pathname"
|
11
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
12
|
+
Pathname.new(__FILE__).realpath)
|
13
|
+
|
14
|
+
require "rubygems"
|
15
|
+
require "bundler/setup"
|
16
|
+
|
17
|
+
load Gem.bin_path("guard", "guard")
|
data/bin/rspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
#
|
4
|
+
# This file was generated by Bundler.
|
5
|
+
#
|
6
|
+
# The application 'rspec' is installed as part of a gem, and
|
7
|
+
# this file is here to facilitate running it.
|
8
|
+
#
|
9
|
+
|
10
|
+
require "pathname"
|
11
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
12
|
+
Pathname.new(__FILE__).realpath)
|
13
|
+
|
14
|
+
require "rubygems"
|
15
|
+
require "bundler/setup"
|
16
|
+
|
17
|
+
load Gem.bin_path("rspec-core", "rspec")
|
data/bin/slice_rename
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
require 'slice_rename/config'
|
4
|
+
require 'slice_rename/slicer'
|
5
|
+
|
6
|
+
module SliceRename
|
7
|
+
class Cli
|
8
|
+
def self.perform
|
9
|
+
config = SliceRename::Config.new
|
10
|
+
|
11
|
+
parser = OptionParser.new do |opts|
|
12
|
+
opts.banner = "Usage: file [options]"
|
13
|
+
|
14
|
+
opts.on("-c", "--config MANDATORY", "A YAML file that contains the slice and name configuration") do |v|
|
15
|
+
config.load v
|
16
|
+
end
|
17
|
+
|
18
|
+
opts.on("-d", "--debug", "Output debug info") do |v|
|
19
|
+
config.debug = true
|
20
|
+
end
|
21
|
+
|
22
|
+
opts.on("-v", "--version", "Display the version") do |v|
|
23
|
+
puts VERSION
|
24
|
+
exit
|
25
|
+
end
|
26
|
+
|
27
|
+
opts.on("-h", "--help", "Display this message") do |v|
|
28
|
+
puts opts
|
29
|
+
exit
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
begin parser.parse! ARGV
|
34
|
+
rescue OptionParser::InvalidOption => e
|
35
|
+
puts e
|
36
|
+
puts parser
|
37
|
+
exit 1
|
38
|
+
end
|
39
|
+
|
40
|
+
arguments = parser.order ARGV
|
41
|
+
if arguments.empty?
|
42
|
+
puts 'Please specify an input file name.'
|
43
|
+
puts parser
|
44
|
+
exit 1
|
45
|
+
else
|
46
|
+
config.path = arguments.first
|
47
|
+
end
|
48
|
+
|
49
|
+
SliceRename::Slicer.slice_image config
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module SliceRename
|
4
|
+
class Config
|
5
|
+
attr_accessor :path, :debug
|
6
|
+
attr_reader :rows, :columns, :width, :height, :padding
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@path = ''
|
10
|
+
@debug = false
|
11
|
+
@rows = 1
|
12
|
+
@columns = 1
|
13
|
+
@width = 16
|
14
|
+
@height = 16
|
15
|
+
@padding = 0
|
16
|
+
@suffixes = []
|
17
|
+
end
|
18
|
+
|
19
|
+
def load(config_path)
|
20
|
+
config = YAML::load_file(File.join(config_path)).fetch('slice_rename_config', {})
|
21
|
+
|
22
|
+
@rows = config.fetch('rows', @rows)
|
23
|
+
@columns = config.fetch('columns', @columns)
|
24
|
+
@width = config.fetch('width', @width)
|
25
|
+
@height = config.fetch('height', @height)
|
26
|
+
@padding = config.fetch('padding', @padding)
|
27
|
+
@suffixes = config.fetch('suffixes', @suffixes)
|
28
|
+
end
|
29
|
+
|
30
|
+
def suffixes
|
31
|
+
count = @rows * @columns
|
32
|
+
|
33
|
+
if @suffixes.count < count
|
34
|
+
@suffixes = []
|
35
|
+
|
36
|
+
for i in 0..(count - 1)
|
37
|
+
@suffixes[i] = "_%02d" % (i + 1)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
@suffixes
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'mini_magick'
|
2
|
+
|
3
|
+
module SliceRename
|
4
|
+
class Slicer
|
5
|
+
def self.slice_image(config)
|
6
|
+
|
7
|
+
extension = File.extname config.path
|
8
|
+
name = File.basename config.path, extension
|
9
|
+
path = File.dirname config.path
|
10
|
+
|
11
|
+
i = 0
|
12
|
+
for y in 0..(config.rows - 1)
|
13
|
+
for x in 0..(config.columns - 1)
|
14
|
+
# Not sure why we need to reload the image each time.
|
15
|
+
image = open_image config.path
|
16
|
+
|
17
|
+
crop = "#{config.width}x#{config.height}+#{x * config.width + (x + 1) * config.padding}+#{y * config.height + (y + 1) * config.padding}"
|
18
|
+
output_name = "#{path}/#{name}#{config.suffixes[i]}#{extension}"
|
19
|
+
|
20
|
+
if config.debug
|
21
|
+
puts crop
|
22
|
+
puts output_name
|
23
|
+
end
|
24
|
+
|
25
|
+
save_slice image, output_name, crop
|
26
|
+
|
27
|
+
i += 1
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def self.open_image(path)
|
35
|
+
MiniMagick::Image.open path
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.save_slice(image, file_name, cropping)
|
39
|
+
image.combine_options do |c|
|
40
|
+
c.crop cropping
|
41
|
+
c.repage.+
|
42
|
+
end
|
43
|
+
|
44
|
+
image.write file_name
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/slice_rename.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
$LOAD_PATH << File.expand_path("../lib", __FILE__)
|
2
|
+
require 'slice_rename'
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'slice_rename'
|
6
|
+
s.version = SliceRename::VERSION
|
7
|
+
s.executables << 'slice_rename'
|
8
|
+
|
9
|
+
s.authors = ['Zoee Silcock']
|
10
|
+
s.email = %q{mrzoee@gmail.com}
|
11
|
+
s.homepage = %q{https://github.com/rocketpants/slice_rename}
|
12
|
+
s.description = %q{Slice an image and give each slice a specific name.}
|
13
|
+
s.summary = %q{Slice an image and give each slice a specific name.}
|
14
|
+
s.licenses = ['MIT']
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {spec}/*`.split("\n")
|
18
|
+
s.require_paths = ['lib']
|
19
|
+
end
|
Binary file
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'slice_rename/config'
|
3
|
+
|
4
|
+
RSpec.describe SliceRename::Config do
|
5
|
+
let(:config) { SliceRename::Config.new }
|
6
|
+
|
7
|
+
describe '#load' do
|
8
|
+
let(:config_path) { 'path/to/my_awesome_config.yml' }
|
9
|
+
|
10
|
+
it 'loads the config file' do
|
11
|
+
expect(YAML).to receive(:load_file) { {} }
|
12
|
+
config.load config_path
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#suffixes' do
|
17
|
+
let!(:suffixes) { ['poop'] }
|
18
|
+
|
19
|
+
it 'returns the supplied suffixes if it has enough' do
|
20
|
+
config.instance_variable_set :@suffixes, suffixes
|
21
|
+
expect(config.suffixes).to eq suffixes
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'returns an auto generated array if suffixes are missing' do
|
25
|
+
config.instance_variable_set :@rows, 2
|
26
|
+
config.instance_variable_set :@columns, 2
|
27
|
+
expect(config.suffixes).to eq ['_01', '_02', '_03', '_04']
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe 'fields' do
|
32
|
+
it 'exposes the input file path' do
|
33
|
+
expect(config.path).to be_a String
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'exposes whether to display debug info' do
|
37
|
+
expect(config.debug).to eq false
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'exposes the number of rows' do
|
41
|
+
expect(config.rows).to be_an Integer
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'exposes the number of columns' do
|
45
|
+
expect(config.columns).to be_an Integer
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'exposes the width of each slice' do
|
49
|
+
expect(config.width).to be_an Integer
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'exposes the height of each slice' do
|
53
|
+
expect(config.height).to be_an Integer
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'exposes the padding between slices' do
|
57
|
+
expect(config.padding).to be_an Integer
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'exposes a list of suffixes for the resulting file names' do
|
61
|
+
expect(config.suffixes).to be_an Array
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'slice_rename/slicer'
|
2
|
+
|
3
|
+
RSpec.describe SliceRename::Slicer do
|
4
|
+
let(:image_double) { double(:image) }
|
5
|
+
let(:config) { SliceRename::Config.new }
|
6
|
+
let(:suffixes) {
|
7
|
+
[
|
8
|
+
'potatoes',
|
9
|
+
'carrots',
|
10
|
+
'onions',
|
11
|
+
'selery'
|
12
|
+
]
|
13
|
+
}
|
14
|
+
|
15
|
+
before do
|
16
|
+
config.instance_variable_set :@rows, 2
|
17
|
+
config.instance_variable_set :@columns, 2
|
18
|
+
config.instance_variable_set :@suffixes, suffixes
|
19
|
+
allow(SliceRename::Slicer).to receive(:open_image) { image_double }
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '.slice_image' do
|
23
|
+
it 'saves the slices with the correct suffixes' do
|
24
|
+
call_count = 0
|
25
|
+
expect(SliceRename::Slicer).to(
|
26
|
+
receive(:save_slice).exactly(4).times do |image, name, cropping|
|
27
|
+
expect(image).to eq(image)
|
28
|
+
expect(name).to include suffixes[call_count]
|
29
|
+
# Should probably test the cropping logic somehow also.
|
30
|
+
|
31
|
+
call_count += 1
|
32
|
+
end
|
33
|
+
)
|
34
|
+
|
35
|
+
SliceRename::Slicer.slice_image config
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
4
|
+
# this file to always be loaded, without a need to explicitly require it in any
|
5
|
+
# files.
|
6
|
+
#
|
7
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
8
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
9
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
10
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
11
|
+
# a separate helper file that requires the additional dependencies and performs
|
12
|
+
# the additional setup, and require it from the spec files that actually need
|
13
|
+
# it.
|
14
|
+
#
|
15
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
16
|
+
# users commonly want.
|
17
|
+
#
|
18
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
19
|
+
RSpec.configure do |config|
|
20
|
+
# rspec-expectations config goes here. You can use an alternate
|
21
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
22
|
+
# assertions if you prefer.
|
23
|
+
config.expect_with :rspec do |expectations|
|
24
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
25
|
+
# and `failure_message` of custom matchers include text for helper methods
|
26
|
+
# defined using `chain`, e.g.:
|
27
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
28
|
+
# # => "be bigger than 2 and smaller than 4"
|
29
|
+
# ...rather than:
|
30
|
+
# # => "be bigger than 2"
|
31
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
32
|
+
end
|
33
|
+
|
34
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
35
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
36
|
+
config.mock_with :rspec do |mocks|
|
37
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
38
|
+
# a real object. This is generally recommended, and will default to
|
39
|
+
# `true` in RSpec 4.
|
40
|
+
mocks.verify_partial_doubles = true
|
41
|
+
end
|
42
|
+
|
43
|
+
# The settings below are suggested to provide a good initial experience
|
44
|
+
# with RSpec, but feel free to customize to your heart's content.
|
45
|
+
=begin
|
46
|
+
# These two settings work together to allow you to limit a spec run
|
47
|
+
# to individual examples or groups you care about by tagging them with
|
48
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
49
|
+
# get run.
|
50
|
+
config.filter_run :focus
|
51
|
+
config.run_all_when_everything_filtered = true
|
52
|
+
|
53
|
+
# Allows RSpec to persist some state between runs in order to support
|
54
|
+
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
55
|
+
# you configure your source control system to ignore this file.
|
56
|
+
config.example_status_persistence_file_path = "spec/examples.txt"
|
57
|
+
|
58
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
59
|
+
# recommended. For more details, see:
|
60
|
+
# - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
|
61
|
+
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
62
|
+
# - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
|
63
|
+
config.disable_monkey_patching!
|
64
|
+
|
65
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
66
|
+
# be too noisy due to issues in dependencies.
|
67
|
+
config.warnings = true
|
68
|
+
|
69
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
70
|
+
# file, and it's useful to allow more verbose output when running an
|
71
|
+
# individual spec file.
|
72
|
+
if config.files_to_run.one?
|
73
|
+
# Use the documentation formatter for detailed output,
|
74
|
+
# unless a formatter has already been configured
|
75
|
+
# (e.g. via a command-line flag).
|
76
|
+
config.default_formatter = 'doc'
|
77
|
+
end
|
78
|
+
|
79
|
+
# Print the 10 slowest examples and example groups at the
|
80
|
+
# end of the spec run, to help surface which specs are running
|
81
|
+
# particularly slow.
|
82
|
+
config.profile_examples = 10
|
83
|
+
|
84
|
+
# Run specs in random order to surface order dependencies. If you find an
|
85
|
+
# order dependency and want to debug it, you can fix the order by providing
|
86
|
+
# the seed, which is printed after each run.
|
87
|
+
# --seed 1234
|
88
|
+
config.order = :random
|
89
|
+
|
90
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
91
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
92
|
+
# test failures related to randomization by passing the same `--seed` value
|
93
|
+
# as the one that triggered the failure.
|
94
|
+
Kernel.srand config.seed
|
95
|
+
=end
|
96
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: slice_rename
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Zoee Silcock
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-08-18 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Slice an image and give each slice a specific name.
|
14
|
+
email: mrzoee@gmail.com
|
15
|
+
executables:
|
16
|
+
- slice_rename
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".rspec"
|
21
|
+
- ".ruby-version"
|
22
|
+
- Gemfile
|
23
|
+
- Gemfile.lock
|
24
|
+
- Guardfile
|
25
|
+
- MIT-LICENSE
|
26
|
+
- README.md
|
27
|
+
- Rakefile
|
28
|
+
- bin/guard
|
29
|
+
- bin/rspec
|
30
|
+
- bin/slice_rename
|
31
|
+
- lib/slice_rename.rb
|
32
|
+
- lib/slice_rename/cli.rb
|
33
|
+
- lib/slice_rename/config.rb
|
34
|
+
- lib/slice_rename/slicer.rb
|
35
|
+
- slice_rename.gemspec
|
36
|
+
- spec/fixtures/animals.png
|
37
|
+
- spec/fixtures/config_example.yml
|
38
|
+
- spec/slice_rename/config_spec.rb
|
39
|
+
- spec/slice_rename/sanity_spec.rb
|
40
|
+
- spec/slice_rename/slicer_spec.rb
|
41
|
+
- spec/spec_helper.rb
|
42
|
+
homepage: https://github.com/rocketpants/slice_rename
|
43
|
+
licenses:
|
44
|
+
- MIT
|
45
|
+
metadata: {}
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
requirements: []
|
61
|
+
rubyforge_project:
|
62
|
+
rubygems_version: 2.5.1
|
63
|
+
signing_key:
|
64
|
+
specification_version: 4
|
65
|
+
summary: Slice an image and give each slice a specific name.
|
66
|
+
test_files: []
|