pt_papersize 0.0.2 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1c94227eceeebfb6fbdc106dc4b874ec8e0a41ce
4
- data.tar.gz: 424f3133e6c0a730b8561f2be277786d3f143df7
3
+ metadata.gz: ad68ee4834a02400b9a43d814d91d8592b7883d1
4
+ data.tar.gz: c23153b8d1b63c549739338529387d5460b63066
5
5
  SHA512:
6
- metadata.gz: e84e080fc01076b4799b296c15c24d372ddab7e34143bde92727cbf16f6bf3fcc0ab940b090846c4ced480148c22c36318d0c956bb80ce4f0527937526a5a95d
7
- data.tar.gz: 4eb3ed1ee2a599d60105645c43123b214ca0a2c8a390abfa19a695311179e8aa20f5be7c38711f68f4a2d464cd62042d448ff9f56e60d9fef96d886476e96bb5
6
+ metadata.gz: 06d220e7e0e2e78ebcb692ab59b12f0d4cbfd0cdfaef2bfadeb35e31d39ca086407dbdf194cc7d88cb4c135b9139abc600954759ded386d599a721ff02bb6ca5
7
+ data.tar.gz: 7fcb4c07fd686f8e7c249807940b91d87332da311573c2e51664c0329685ad829203b0118961a0f916348dba9579e70ee2111ee5072df037f585d39877cff414
@@ -3,31 +3,27 @@ require 'pt/papersize/paper_sizes'
3
3
 
4
4
  module PT
5
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
6
+ def self.find(width, height, units = :pt)
7
+ short_edge = [width, height].min
8
+ long_edge = [width, height].max
17
9
 
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
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
- 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)
23
+ (short_edge_mm == entry[:width]) && (long_edge_mm == entry[:height])
28
24
  end
29
25
 
30
- available_sizes.length > 0 ? available_sizes.first[:name] : 'Custom'
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
- { 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 },
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: '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 },
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: '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 },
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
+
@@ -1,5 +1,5 @@
1
1
  module PT
2
2
  class PaperSize
3
- VERSION = "0.0.2"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
@@ -1,13 +1,18 @@
1
1
  require 'pt/papersize'
2
2
 
3
3
  describe PT::PaperSize do
4
- it "names ISO A4" do
5
- pt_papersize = PT::PaperSize.new(842,595)
6
- pt_papersize.name.should eq('A4')
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
- pt_papersize = PT::PaperSize.new(120,20)
11
- pt_papersize.name.should eq('Custom')
16
+ PT::PaperSize.find(120,20,:mm)[:name].should eq('Custom')
12
17
  end
13
18
  end
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'pt/papersize'
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.0.2
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-16 00:00:00.000000000 Z
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