hamidashi 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0a767e6d490ad96dfc9c40f3f89686dfd9e52361
4
- data.tar.gz: 444bec65a0b05297c2faddf32175cef233c9e265
3
+ metadata.gz: a54739c578438bb92798c9a9013558814ae8bab8
4
+ data.tar.gz: 16a9cbaaba7112a9884bd44dc2cae7bd66e16192
5
5
  SHA512:
6
- metadata.gz: 5e6c06b86b4e4cd05ae2f2e9325103061645671594a1ce3e2a482b1d7d137b861b54ac067523c6a27ff9b423006bfc15a9fa43be67bd4b2ef0f17fa71b5147f7
7
- data.tar.gz: 209c92e74c6fe93a428377f7641ce7c35ccd0e6d7da5da153c42b5844c692544529f449e1cbdf8b9b1ee41a596bac7b68410c3553057c0992a24c983baec3c2b
6
+ metadata.gz: c411396049bb39b3307a50e0c2af21591084fdfea7a853d89cf3da635d2f4e46f935ea6d13554b82e340171e294b50c7b3e813c1e6b3f92dabe22c3f60740fb9
7
+ data.tar.gz: 5b9b038f11aabf3eb66dcd97272576c7d44ec0d72085916d46102fbf00b8552f4cd4a7721d64429dcfab3a3c6c3b6c7b4eaf4038e4cc8acd109deea78023c629
@@ -19,7 +19,7 @@ Options:
19
19
  -h --help Show this screen.
20
20
  --version Show version.
21
21
  --page=<page> Show specified page [default: 10].
22
- --margin=<margin> Right margin percentage [default: 4.375].
22
+ --margin=<margin> Right margin [default: 4.375%].
23
23
  DOCOPT
24
24
 
25
25
  begin
@@ -39,7 +39,14 @@ if opt['--version']
39
39
  end
40
40
 
41
41
  pdf_path = File.expand_path(opt['<name>'])
42
- hamidashi = Hamidashi.new(Rational(opt['--margin']), pdf_path)
42
+
43
+ unless /\A[\d.]+(%|px|)\z/ =~ opt['--margin']
44
+ puts "margin #{opt['--margin']} is invalid."
45
+ puts 'example: 42% or 42px or 42'
46
+ exit 1
47
+ end
48
+
49
+ hamidashi = Hamidashi.new(opt['--margin'], pdf_path)
43
50
 
44
51
  if opt['preview']
45
52
  preview_path = File.expand_path("hamidashi-preview-#{Time.now.strftime("%Y%m%d%H%M%S")}-" + File.basename(pdf_path, '.pdf') + "-#{opt['--page']}.png")
@@ -1,12 +1,10 @@
1
1
  require "hamidashi/version"
2
- require "RMagick"
2
+ require "rmagick"
3
3
 
4
4
  class Hamidashi
5
- attr_reader :percentage
6
-
7
- def initialize(percentage, pdf_path)
8
- @percentage = percentage / 100r
9
- @pdf_path = pdf_path
5
+ def initialize(margin, pdf_path)
6
+ @margin = margin
7
+ @pdf_path = pdf_path
10
8
  end
11
9
 
12
10
  def overflow?(page)
@@ -59,12 +57,26 @@ class Hamidashi
59
57
  1
60
58
  end
61
59
 
60
+ def fixed_margin?
61
+ @margin.end_with?('px')
62
+ end
63
+
64
+ def margin_px
65
+ @margin_width ||= Integer(@margin.sub('px', ''))
66
+ end
67
+
68
+ def margin_percentage
69
+ @margin_percentage ||= Rational(@margin.sub('%', '')) / 100
70
+ end
71
+
62
72
  def pdf_image_list
63
73
  @pdf_image_list ||= Magick::ImageList.new(@pdf_path)
64
74
  end
65
75
 
66
76
  def right_margin_width(page)
77
+ return margin_px if fixed_margin?
78
+
67
79
  page_img = pdf_image_list[page]
68
- (page_img.columns * percentage).to_i
80
+ (page_img.columns * margin_percentage).to_i
69
81
  end
70
82
  end
@@ -1,3 +1,3 @@
1
1
  class Hamidashi
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hamidashi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seiei Miyagi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-07-18 00:00:00.000000000 Z
11
+ date: 2015-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: docopt