label_definitions 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +46 -0
- data/Rakefile +10 -0
- data/label_definitions.gemspec +26 -0
- data/labels.yml +56 -0
- data/lib/label_definitions/label.rb +24 -0
- data/lib/label_definitions/version.rb +3 -0
- data/lib/label_definitions.rb +45 -0
- data/test/helper.rb +8 -0
- data/test/label_definitions_test.rb +54 -0
- data/test/label_test.rb +24 -0
- metadata +116 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Andy Stewart
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# Label Definitions
|
2
|
+
|
3
|
+
An open source list of label dimensions. The data are in [labels.yml](./labels.yml).
|
4
|
+
|
5
|
+
Surprisingly Avery doesn't publish a structured list of their labels. Even more surprisingly, I can't find a good list on the internet. So here's a start.
|
6
|
+
|
7
|
+
Avery has so many labels that I add them here on an as-needed basis. Feel free to open a pull request for additional labels (supplying the dimensions).
|
8
|
+
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
gem 'label_definitions'
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install label_definitions
|
23
|
+
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
# Get all the labels
|
29
|
+
LabelDefinitions.all
|
30
|
+
# => [ #<Label>, ... ]
|
31
|
+
|
32
|
+
# Get a specific label
|
33
|
+
LabelDefinitions.find 'Avery 5160'
|
34
|
+
# => #<Label @name='Avery 5160', ...>
|
35
|
+
|
36
|
+
# Add a custom label (not persisted)
|
37
|
+
custom = Label.new name: 'Custom', ...
|
38
|
+
LabelDefinitions.add custom
|
39
|
+
LabelDefinitions.find 'Custom'
|
40
|
+
# => #<Label @name='Custom', ...>
|
41
|
+
```
|
42
|
+
|
43
|
+
|
44
|
+
## Intellectual Property
|
45
|
+
|
46
|
+
Copyright 2013 Andrew Stewart, AirBlade Software Ltd. Released under the MIT licence.
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'label_definitions/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "label_definitions"
|
8
|
+
spec.version = LabelDefinitions::VERSION
|
9
|
+
spec.authors = ["Andy Stewart"]
|
10
|
+
spec.email = ["boss@airbladesoftware.com"]
|
11
|
+
spec.description = 'Open source list of label sizes.'
|
12
|
+
spec.summary = 'Open source list of label sizes.'
|
13
|
+
spec.homepage = 'https://github.com/airblade/label_definitions'
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency 'minitest', '~> 5'
|
24
|
+
end
|
25
|
+
|
26
|
+
|
data/labels.yml
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# Listed alphabetically.
|
2
|
+
# Labels with the same dimensions are listed once with aliases.
|
3
|
+
# Specify either page_size or (page_width and page_height).
|
4
|
+
# Dimensions in millimetres.
|
5
|
+
|
6
|
+
Avery 3657:
|
7
|
+
rows: 10
|
8
|
+
columns: 4
|
9
|
+
width: 48.5
|
10
|
+
height: 25.4
|
11
|
+
row_gutter: 0.0
|
12
|
+
column_gutter: 0.0
|
13
|
+
page_size: A4
|
14
|
+
Avery 5160:
|
15
|
+
rows: 10
|
16
|
+
columns: 3
|
17
|
+
width: 66.675
|
18
|
+
height: 25.4
|
19
|
+
row_gutter: 0.0
|
20
|
+
column_gutter: 3.175
|
21
|
+
page_size: Letter
|
22
|
+
Avery 5395:
|
23
|
+
rows: 4
|
24
|
+
columns: 2
|
25
|
+
width: 85.725
|
26
|
+
height: 59.267
|
27
|
+
row_gutter: 4.0527
|
28
|
+
column_gutter: 9.5
|
29
|
+
page_size: Letter
|
30
|
+
Avery 5418:
|
31
|
+
rows: 9
|
32
|
+
columns: 4
|
33
|
+
width: 19.05
|
34
|
+
height: 12.7
|
35
|
+
row_gutter: 1.6
|
36
|
+
column_gutter: 1.6
|
37
|
+
page_width: 101.6
|
38
|
+
page_height: 152.4
|
39
|
+
Avery J8651:
|
40
|
+
aliases: Avery L7651
|
41
|
+
rows: 13
|
42
|
+
columns: 5
|
43
|
+
width: 38.1
|
44
|
+
height: 21.2
|
45
|
+
row_gutter: 0.0
|
46
|
+
column_gutter: 2.5
|
47
|
+
page_size: A4
|
48
|
+
Zweckform 4737:
|
49
|
+
aliases: Zweckform 4784
|
50
|
+
rows: 9
|
51
|
+
columns: 3
|
52
|
+
width: 63.5
|
53
|
+
height: 29.6
|
54
|
+
row_gutter: 0.0
|
55
|
+
column_gutter: 2.54
|
56
|
+
page_size: A4
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module LabelDefinitions
|
2
|
+
class Label
|
3
|
+
attr_reader :name, :rows, :columns, :width, :height, :row_gutter, :column_gutter,
|
4
|
+
:page_size, :page_width, :page_height
|
5
|
+
|
6
|
+
def initialize(attributes = {})
|
7
|
+
@name = attributes.fetch(:name)
|
8
|
+
@rows = attributes.fetch(:rows).to_i
|
9
|
+
@columns = attributes.fetch(:columns).to_i
|
10
|
+
@width = attributes.fetch(:width).to_f
|
11
|
+
@height = attributes.fetch(:height).to_f
|
12
|
+
@row_gutter = attributes.fetch(:row_gutter).to_f
|
13
|
+
@column_gutter = attributes.fetch(:column_gutter).to_f
|
14
|
+
if attributes.has_key? :page_size
|
15
|
+
@page_size = attributes.fetch(:page_size)
|
16
|
+
else
|
17
|
+
@page_width = attributes.fetch(:page_width).to_f
|
18
|
+
@page_height = attributes.fetch(:page_height).to_f
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'label_definitions/label'
|
3
|
+
require 'label_definitions/version'
|
4
|
+
|
5
|
+
module LabelDefinitions
|
6
|
+
|
7
|
+
def self.all
|
8
|
+
@labels ||= begin
|
9
|
+
labels = []
|
10
|
+
load_definitions.each do |name, definition|
|
11
|
+
symbolize_keys! definition
|
12
|
+
name_and_aliases(name, definition).each do |n|
|
13
|
+
labels << Label.new(definition.merge({name: n}))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
labels
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.find(name)
|
21
|
+
all.detect { |label| label.name == name }
|
22
|
+
end
|
23
|
+
|
24
|
+
# Adds a label definition to the in-memory list. Does not persist it.
|
25
|
+
def self.add(label)
|
26
|
+
find(label.name) || (all << label)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def self.name_and_aliases(name, definition)
|
32
|
+
[name] + definition.fetch(:aliases, '').split(',').map(&:strip)
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.load_definitions
|
36
|
+
YAML.load_file File.expand_path('../../labels.yml', __FILE__)
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.symbolize_keys!(hash)
|
40
|
+
hash.keys.each do |key|
|
41
|
+
hash[key.to_sym] = hash.delete key
|
42
|
+
end
|
43
|
+
hash
|
44
|
+
end
|
45
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
require 'label_definitions'
|
3
|
+
|
4
|
+
class LabelDefinitionsTest < TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
LabelDefinitions.instance_variable_set '@labels', nil
|
8
|
+
end
|
9
|
+
|
10
|
+
test 'all' do
|
11
|
+
labels = LabelDefinitions.all
|
12
|
+
assert_same labels, LabelDefinitions.all # caching
|
13
|
+
assert_equal 8, labels.length
|
14
|
+
assert_kind_of LabelDefinitions::Label, labels.first
|
15
|
+
end
|
16
|
+
|
17
|
+
test 'find' do
|
18
|
+
label = LabelDefinitions.find 'Zweckform 4737'
|
19
|
+
assert_equal 9, label.rows
|
20
|
+
end
|
21
|
+
|
22
|
+
test 'find alias' do
|
23
|
+
label = LabelDefinitions.find 'Zweckform 4784'
|
24
|
+
assert_equal 9, label.rows
|
25
|
+
end
|
26
|
+
|
27
|
+
test 'add custom label' do
|
28
|
+
custom = example_label
|
29
|
+
LabelDefinitions.add custom
|
30
|
+
label = LabelDefinitions.find 'Custom'
|
31
|
+
assert_same custom, label
|
32
|
+
end
|
33
|
+
|
34
|
+
test 'add custom label ignores duplicates' do
|
35
|
+
LabelDefinitions.add example_label
|
36
|
+
count = LabelDefinitions.all.length
|
37
|
+
LabelDefinitions.add example_label
|
38
|
+
assert_equal count, LabelDefinitions.all.length
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def example_label
|
44
|
+
LabelDefinitions::Label.new name: 'Custom',
|
45
|
+
rows: 3,
|
46
|
+
columns: 5,
|
47
|
+
width: 153,
|
48
|
+
height: 42,
|
49
|
+
row_gutter: 0,
|
50
|
+
column_gutter: 0,
|
51
|
+
page_size: 'A4'
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
data/test/label_test.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
require 'label_definitions/label'
|
3
|
+
|
4
|
+
class LabelTest < TestCase
|
5
|
+
|
6
|
+
test 'requires page size or (page width and height)' do
|
7
|
+
assert_raises(KeyError) { LabelDefinitions::Label.new attributes }
|
8
|
+
assert LabelDefinitions::Label.new(attributes.merge(page_size: 'A4'))
|
9
|
+
assert LabelDefinitions::Label.new(attributes.merge(page_width: 42, page_height: 153))
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def attributes
|
15
|
+
{ name: 'Some label',
|
16
|
+
rows: 3,
|
17
|
+
columns: 5,
|
18
|
+
width: 153,
|
19
|
+
height: 42,
|
20
|
+
row_gutter: 0,
|
21
|
+
column_gutter: 0 }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: label_definitions
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Andy Stewart
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-11-20 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: minitest
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '5'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5'
|
62
|
+
description: Open source list of label sizes.
|
63
|
+
email:
|
64
|
+
- boss@airbladesoftware.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- Gemfile
|
71
|
+
- LICENSE.txt
|
72
|
+
- README.md
|
73
|
+
- Rakefile
|
74
|
+
- label_definitions.gemspec
|
75
|
+
- labels.yml
|
76
|
+
- lib/label_definitions.rb
|
77
|
+
- lib/label_definitions/label.rb
|
78
|
+
- lib/label_definitions/version.rb
|
79
|
+
- test/helper.rb
|
80
|
+
- test/label_definitions_test.rb
|
81
|
+
- test/label_test.rb
|
82
|
+
homepage: https://github.com/airblade/label_definitions
|
83
|
+
licenses:
|
84
|
+
- MIT
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
segments:
|
96
|
+
- 0
|
97
|
+
hash: 3975846568932287638
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
segments:
|
105
|
+
- 0
|
106
|
+
hash: 3975846568932287638
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 1.8.23
|
110
|
+
signing_key:
|
111
|
+
specification_version: 3
|
112
|
+
summary: Open source list of label sizes.
|
113
|
+
test_files:
|
114
|
+
- test/helper.rb
|
115
|
+
- test/label_definitions_test.rb
|
116
|
+
- test/label_test.rb
|