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 +4 -4
- data/exe/hamidashi +9 -2
- data/lib/hamidashi.rb +19 -7
- data/lib/hamidashi/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a54739c578438bb92798c9a9013558814ae8bab8
|
4
|
+
data.tar.gz: 16a9cbaaba7112a9884bd44dc2cae7bd66e16192
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c411396049bb39b3307a50e0c2af21591084fdfea7a853d89cf3da635d2f4e46f935ea6d13554b82e340171e294b50c7b3e813c1e6b3f92dabe22c3f60740fb9
|
7
|
+
data.tar.gz: 5b9b038f11aabf3eb66dcd97272576c7d44ec0d72085916d46102fbf00b8552f4cd4a7721d64429dcfab3a3c6c3b6c7b4eaf4038e4cc8acd109deea78023c629
|
data/exe/hamidashi
CHANGED
@@ -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
|
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
|
-
|
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")
|
data/lib/hamidashi.rb
CHANGED
@@ -1,12 +1,10 @@
|
|
1
1
|
require "hamidashi/version"
|
2
|
-
require "
|
2
|
+
require "rmagick"
|
3
3
|
|
4
4
|
class Hamidashi
|
5
|
-
|
6
|
-
|
7
|
-
|
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 *
|
80
|
+
(page_img.columns * margin_percentage).to_i
|
69
81
|
end
|
70
82
|
end
|
data/lib/hamidashi/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2015-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: docopt
|