pt_papersize 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ebbbf2036a3420d9180e46a20eef0f74348b5299
4
+ data.tar.gz: ac9910e309b900cc6c81fcd8ec26db6bc635b7de
5
+ SHA512:
6
+ metadata.gz: 82a03d4d61865cb0b70ed18c4ba2f671230c2479c168b048abb1b44adeeb1f5866cce51ae8cae6e1e0233e788f615624f7579897917e90784e6f77612094f80f
7
+ data.tar.gz: b9474ce3f3545d7746677e05f6b567def248ef3431a3dfaff3491b0987652bf235769ef8555a207117c1dd0790cc7d4a6eab560ef1c9ba7ef883a0a9fbbf334a
data/.gitignore ADDED
@@ -0,0 +1,36 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /lib/bundler/man/
26
+
27
+ # for a library or gem, you might want to ignore these files since the code is
28
+ # intended to run in multiple environments; otherwise, check them in:
29
+ # Gemfile.lock
30
+ # .ruby-version
31
+ # .ruby-gemset
32
+
33
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
34
+ .rvmrc
35
+
36
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "http://rubygems.org"
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Paul Chilton
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # pt_papersize
2
+
3
+ Identify standard page sizes from PostScript point sizes. Based on info at:
4
+
5
+ http://en.wikipedia.org/wiki/Paper_size
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'pt_papersize'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install pt_papersize
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ require 'pt/papersize'
25
+ papersize = PT::PaperSize.new(595,842)
26
+ puts papersize.name
27
+ ```
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it ( https://github.com/pchilton/pt_papersize/fork )
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,41 @@
1
+ module PT
2
+ class PaperSize
3
+ PAPER_SIZES = [
4
+ { name: 'A0', standard: 'ISO', width: 841, height: 1189 },
5
+ { name: 'A1', standard: 'ISO', width: 594, height: 841 },
6
+ { name: 'A2', standard: 'ISO', width: 420, height: 594 },
7
+ { name: 'A3', standard: 'ISO', width: 297, height: 420 },
8
+ { name: 'A4', standard: 'ISO', width: 210, height: 297 },
9
+ { name: 'A5', standard: 'ISO', width: 148, height: 210 },
10
+ { name: 'A6', standard: 'ISO', width: 105, height: 148 },
11
+ { name: 'A7', standard: 'ISO', width: 74, height: 105 },
12
+ { name: 'A8', standard: 'ISO', width: 52, height: 74 },
13
+ { name: 'A9', standard: 'ISO', width: 37, height: 52 },
14
+ { name: 'A10', standard: 'ISO', width: 26, height: 37 },
15
+
16
+ { name: 'B0', standard: 'ISO', width: 1000, height: 1414 },
17
+ { name: 'B1', standard: 'ISO', width: 707, height: 1000 },
18
+ { name: 'B2', standard: 'ISO', width: 500, height: 707 },
19
+ { name: 'B3', standard: 'ISO', width: 353, height: 500 },
20
+ { name: 'B4', standard: 'ISO', width: 250, height: 353 },
21
+ { name: 'B5', standard: 'ISO', width: 176, height: 250 },
22
+ { name: 'B6', standard: 'ISO', width: 125, height: 176 },
23
+ { name: 'B7', standard: 'ISO', width: 88, height: 125 },
24
+ { name: 'B8', standard: 'ISO', width: 62, height: 88 },
25
+ { name: 'B9', standard: 'ISO', width: 44, height: 62 },
26
+ { name: 'B10', standard: 'ISO', width: 31, height: 44 },
27
+
28
+ { name: 'C0', standard: 'ISO', width: 917, height: 1297 },
29
+ { name: 'C1', standard: 'ISO', width: 648, height: 917 },
30
+ { name: 'C2', standard: 'ISO', width: 458, height: 648 },
31
+ { name: 'C3', standard: 'ISO', width: 324, height: 458 },
32
+ { name: 'C4', standard: 'ISO', width: 229, height: 324 },
33
+ { name: 'C5', standard: 'ISO', width: 162, height: 229 },
34
+ { name: 'C6', standard: 'ISO', width: 114, height: 162 },
35
+ { name: 'C7', standard: 'ISO', width: 81, height: 114 },
36
+ { name: 'C8', standard: 'ISO', width: 57, height: 81 },
37
+ { name: 'C9', standard: 'ISO', width: 40, height: 57 },
38
+ { name: 'C10', standard: 'ISO', width: 28, height: 40 },
39
+ ]
40
+ end
41
+ end
@@ -0,0 +1,5 @@
1
+ module PT
2
+ class PaperSize
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,33 @@
1
+ require 'pt/papersize/version'
2
+ require 'pt/papersize/paper_sizes'
3
+
4
+ module PT
5
+ class PaperSize
6
+ def initialize(width, height)
7
+ @width = width
8
+ @height = height
9
+ end
10
+
11
+ def name
12
+ short_edge_pt = [@width,@height].min
13
+ long_edge_pt = [@width,@height].max
14
+
15
+ short_edge_mm = (short_edge_pt.to_f / 72.0) * 25.4
16
+ long_edge_mm = (long_edge_pt.to_f / 72.0) * 25.4
17
+
18
+ short_edge_floor = short_edge_mm.floor
19
+ short_edge_ceil = short_edge_mm.ceil
20
+
21
+ long_edge_floor = long_edge_mm.floor
22
+ long_edge_ceil = long_edge_mm.ceil
23
+
24
+ available_sizes = PT::PaperSize::PAPER_SIZES.select do |entry|
25
+ paper_short = [entry[:width], entry[:height]].min
26
+ paper_long = [entry[:width], entry[:height]].max
27
+ (paper_short == short_edge_floor || paper_short == short_edge_ceil) && (paper_long == long_edge_floor || paper_long == long_edge_ceil)
28
+ end
29
+
30
+ available_sizes.length > 0 ? available_sizes.first[:name] : 'Custom'
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pt/papersize/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "pt_papersize"
8
+ spec.version = PT::PaperSize::VERSION
9
+ spec.authors = ["Paul Chilton"]
10
+ spec.email = ["paul.chilton@gmail.com"]
11
+ spec.summary = %q{Identify standard page sizes from PostScript point sizes}
12
+ spec.homepage = "https://github.com/pchilton/pt_papersize"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.6"
21
+ spec.add_development_dependency "rake"
22
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pt_papersize
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Paul Chilton
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description:
42
+ email:
43
+ - paul.chilton@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE
51
+ - README.md
52
+ - Rakefile
53
+ - lib/pt/papersize.rb
54
+ - lib/pt/papersize/paper_sizes.rb
55
+ - lib/pt/papersize/version.rb
56
+ - pt_papersize.gemspec
57
+ homepage: https://github.com/pchilton/pt_papersize
58
+ licenses:
59
+ - MIT
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 2.2.2
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: Identify standard page sizes from PostScript point sizes
81
+ test_files: []