pt_papersize 0.0.2 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pt/papersize.rb +16 -20
- data/lib/pt/papersize/paper_sizes.rb +53 -33
- data/lib/pt/papersize/version.rb +1 -1
- data/spec/pt_papersize_spec.rb +10 -5
- data/spec/spec_helper.rb +3 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad68ee4834a02400b9a43d814d91d8592b7883d1
|
4
|
+
data.tar.gz: c23153b8d1b63c549739338529387d5460b63066
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06d220e7e0e2e78ebcb692ab59b12f0d4cbfd0cdfaef2bfadeb35e31d39ca086407dbdf194cc7d88cb4c135b9139abc600954759ded386d599a721ff02bb6ca5
|
7
|
+
data.tar.gz: 7fcb4c07fd686f8e7c249807940b91d87332da311573c2e51664c0329685ad829203b0118961a0f916348dba9579e70ee2111ee5072df037f585d39877cff414
|
data/lib/pt/papersize.rb
CHANGED
@@ -3,31 +3,27 @@ require 'pt/papersize/paper_sizes'
|
|
3
3
|
|
4
4
|
module PT
|
5
5
|
class PaperSize
|
6
|
-
def
|
7
|
-
|
8
|
-
|
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
|
6
|
+
def self.find(width, height, units = :pt)
|
7
|
+
short_edge = [width, height].min
|
8
|
+
long_edge = [width, height].max
|
17
9
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
10
|
+
case units
|
11
|
+
when :pt, :point, :points
|
12
|
+
short_edge_mm = ((short_edge.to_f / 72.0) * 25.4).round
|
13
|
+
long_edge_mm = ((long_edge.to_f / 72.0) * 25.4).round
|
14
|
+
when :mm, :millimetre, :millimetres
|
15
|
+
short_edge_mm = short_edge
|
16
|
+
long_edge_mm = long_edge
|
17
|
+
when :inch, :inches
|
18
|
+
short_edge_mm = (short_edge.to_f * 25.4).round
|
19
|
+
long_edge_mm = (long_edge.to_f * 25.4).round
|
20
|
+
end
|
23
21
|
|
24
22
|
available_sizes = PT::PaperSize::PAPER_SIZES.select do |entry|
|
25
|
-
|
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)
|
23
|
+
(short_edge_mm == entry[:width]) && (long_edge_mm == entry[:height])
|
28
24
|
end
|
29
25
|
|
30
|
-
available_sizes.length > 0 ? available_sizes.first
|
26
|
+
available_sizes.length > 0 ? available_sizes.first : { name: 'Custom', width: short_edge_mm, height: long_edge_mm, units: :mm}
|
31
27
|
end
|
32
28
|
end
|
33
29
|
end
|
@@ -1,41 +1,61 @@
|
|
1
1
|
module PT
|
2
2
|
class PaperSize
|
3
3
|
PAPER_SIZES = [
|
4
|
-
|
5
|
-
{ name: '
|
6
|
-
{ name: '
|
7
|
-
{ name: '
|
8
|
-
{ name: '
|
9
|
-
{ name: '
|
10
|
-
{ name: '
|
11
|
-
{ name: '
|
12
|
-
{ name: '
|
13
|
-
{ name: '
|
14
|
-
{ name: '
|
4
|
+
# ISO paper sizes
|
5
|
+
{ name: 'A0', standard: 'ISO216', width: 841, height: 1189 },
|
6
|
+
{ name: 'A1', standard: 'ISO216', width: 594, height: 841 },
|
7
|
+
{ name: 'A2', standard: 'ISO216', width: 420, height: 594 },
|
8
|
+
{ name: 'A3', standard: 'ISO216', width: 297, height: 420 },
|
9
|
+
{ name: 'A4', standard: 'ISO216', width: 210, height: 297 },
|
10
|
+
{ name: 'A5', standard: 'ISO216', width: 148, height: 210 },
|
11
|
+
{ name: 'A6', standard: 'ISO216', width: 105, height: 148 },
|
12
|
+
{ name: 'A7', standard: 'ISO216', width: 74, height: 105 },
|
13
|
+
{ name: 'A8', standard: 'ISO216', width: 52, height: 74 },
|
14
|
+
{ name: 'A9', standard: 'ISO216', width: 37, height: 52 },
|
15
|
+
{ name: 'A10', standard: 'ISO216', width: 26, height: 37 },
|
15
16
|
|
16
|
-
{ name: 'B0', standard: '
|
17
|
-
{ name: 'B1', standard: '
|
18
|
-
{ name: 'B2', standard: '
|
19
|
-
{ name: 'B3', standard: '
|
20
|
-
{ name: 'B4', standard: '
|
21
|
-
{ name: 'B5', standard: '
|
22
|
-
{ name: 'B6', standard: '
|
23
|
-
{ name: 'B7', standard: '
|
24
|
-
{ name: 'B8', standard: '
|
25
|
-
{ name: 'B9', standard: '
|
26
|
-
{ name: 'B10', standard: '
|
17
|
+
{ name: 'B0', standard: 'ISO216', width: 1000, height: 1414 },
|
18
|
+
{ name: 'B1', standard: 'ISO216', width: 707, height: 1000 },
|
19
|
+
{ name: 'B2', standard: 'ISO216', width: 500, height: 707 },
|
20
|
+
{ name: 'B3', standard: 'ISO216', width: 353, height: 500 },
|
21
|
+
{ name: 'B4', standard: 'ISO216', width: 250, height: 353 },
|
22
|
+
{ name: 'B5', standard: 'ISO216', width: 176, height: 250 },
|
23
|
+
{ name: 'B6', standard: 'ISO216', width: 125, height: 176 },
|
24
|
+
{ name: 'B7', standard: 'ISO216', width: 88, height: 125 },
|
25
|
+
{ name: 'B8', standard: 'ISO216', width: 62, height: 88 },
|
26
|
+
{ name: 'B9', standard: 'ISO216', width: 44, height: 62 },
|
27
|
+
{ name: 'B10', standard: 'ISO216', width: 31, height: 44 },
|
27
28
|
|
28
|
-
{ name: 'C0', standard: '
|
29
|
-
{ name: 'C1', standard: '
|
30
|
-
{ name: 'C2', standard: '
|
31
|
-
{ name: 'C3', standard: '
|
32
|
-
{ name: 'C4', standard: '
|
33
|
-
{ name: 'C5', standard: '
|
34
|
-
{ name: 'C6', standard: '
|
35
|
-
{ name: 'C7', standard: '
|
36
|
-
{ name: 'C8', standard: '
|
37
|
-
{ name: 'C9', standard: '
|
38
|
-
{ name: 'C10', standard: '
|
29
|
+
{ name: 'C0', standard: 'ISO216', width: 917, height: 1297 },
|
30
|
+
{ name: 'C1', standard: 'ISO216', width: 648, height: 917 },
|
31
|
+
{ name: 'C2', standard: 'ISO216', width: 458, height: 648 },
|
32
|
+
{ name: 'C3', standard: 'ISO216', width: 324, height: 458 },
|
33
|
+
{ name: 'C4', standard: 'ISO216', width: 229, height: 324 },
|
34
|
+
{ name: 'C5', standard: 'ISO216', width: 162, height: 229 },
|
35
|
+
{ name: 'C6', standard: 'ISO216', width: 114, height: 162 },
|
36
|
+
{ name: 'C7', standard: 'ISO216', width: 81, height: 114 },
|
37
|
+
{ name: 'C8', standard: 'ISO216', width: 57, height: 81 },
|
38
|
+
{ name: 'C9', standard: 'ISO216', width: 40, height: 57 },
|
39
|
+
{ name: 'C10', standard: 'ISO216', width: 28, height: 40 },
|
40
|
+
|
41
|
+
# Other metric sizes
|
42
|
+
{ name: 'DL', width: 99, height: 210 },
|
43
|
+
{ name: 'DLE', width: 110, height: 220 },
|
44
|
+
{ name: 'F4', width: 210, height: 330 },
|
45
|
+
{ name: 'RA0', width: 841, height: 1189 },
|
46
|
+
{ name: 'RA1', width: 610, height: 860 },
|
47
|
+
{ name: 'RA2', width: 430, height: 610 },
|
48
|
+
{ name: 'RA3', width: 305, height: 430 },
|
49
|
+
{ name: 'RA4', width: 215, height: 305 },
|
50
|
+
{ name: 'SRA0', width: 900, height: 1280 },
|
51
|
+
{ name: 'SRA1', width: 640, height: 900 },
|
52
|
+
{ name: 'SRA2', width: 450, height: 640 },
|
53
|
+
{ name: 'SRA3', width: 320, height: 450 },
|
54
|
+
{ name: 'SRA4', width: 225, height: 320 },
|
55
|
+
{ name: 'A3+', width: 29, height: 483 },
|
39
56
|
]
|
40
57
|
end
|
41
58
|
end
|
59
|
+
|
60
|
+
|
61
|
+
|
data/lib/pt/papersize/version.rb
CHANGED
data/spec/pt_papersize_spec.rb
CHANGED
@@ -1,13 +1,18 @@
|
|
1
1
|
require 'pt/papersize'
|
2
2
|
|
3
3
|
describe PT::PaperSize do
|
4
|
-
it "names ISO A4" do
|
5
|
-
|
6
|
-
|
4
|
+
it "names ISO A4 from PostScript points" do
|
5
|
+
PT::PaperSize.find(595,842,:pt)[:name].should eq('A4')
|
6
|
+
PT::PaperSize.find(842,595,:pt)[:name].should eq('A4')
|
7
|
+
end
|
8
|
+
|
9
|
+
it "names SRA3 from various units" do
|
10
|
+
PT::PaperSize.find(320,450,:mm)[:name].should eq('SRA3')
|
11
|
+
PT::PaperSize.find(907,1276,:pt)[:name].should eq('SRA3')
|
12
|
+
PT::PaperSize.find(12.6,17.7,:inch)[:name].should eq('SRA3')
|
7
13
|
end
|
8
14
|
|
9
15
|
it "names random size as Custom" do
|
10
|
-
|
11
|
-
pt_papersize.name.should eq('Custom')
|
16
|
+
PT::PaperSize.find(120,20,:mm)[:name].should eq('Custom')
|
12
17
|
end
|
13
18
|
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pt_papersize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Chilton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -69,6 +69,7 @@ files:
|
|
69
69
|
- lib/pt/papersize/version.rb
|
70
70
|
- pt_papersize.gemspec
|
71
71
|
- spec/pt_papersize_spec.rb
|
72
|
+
- spec/spec_helper.rb
|
72
73
|
homepage: https://github.com/pchilton/pt_papersize
|
73
74
|
licenses:
|
74
75
|
- MIT
|
@@ -95,3 +96,4 @@ specification_version: 4
|
|
95
96
|
summary: Identify standard page sizes from PostScript point sizes
|
96
97
|
test_files:
|
97
98
|
- spec/pt_papersize_spec.rb
|
99
|
+
- spec/spec_helper.rb
|