mk_semi_lattice 0.3.1 → 0.4.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 +4 -4
- data/.semi_lattice/icons/document.png +0 -0
- data/.semi_lattice/icons/folder.png +0 -0
- data/README.org +30 -33
- data/exe/hc +3 -0
- data/lib/.semi_lattice/icons/document.png +0 -0
- data/lib/.semi_lattice/icons/folder.png +0 -0
- data/lib/hc.rb +34 -0
- data/lib/mk_semi_lattice/.semi_lattice/icons/document.png +0 -0
- data/lib/mk_semi_lattice/.semi_lattice/icons/folder.png +0 -0
- data/lib/mk_semi_lattice/docs/images/mk_semi_lattice.001.png +0 -0
- data/lib/mk_semi_lattice/docs/images/mk_semi_lattice.002.png +0 -0
- data/lib/mk_semi_lattice/docs/images/mk_semi_lattice.003.png +0 -0
- data/lib/mk_semi_lattice/docs/images/mk_semi_lattice.key +0 -0
- data/lib/mk_semi_lattice/docs/readme.html +143 -0
- data/lib/mk_semi_lattice/docs/readme.org +50 -0
- data/lib/mk_semi_lattice/option_manager.rb +9 -8
- data/lib/mk_semi_lattice/version.rb +1 -1
- data/lib/mk_semi_lattice.rb +8 -3
- data/lib/mk_stack/.semi_lattice/icons/document.png +0 -0
- data/lib/mk_stack/.semi_lattice/icons/folder.png +0 -0
- data/lib/mk_stack/.vscode/settings.json +4 -0
- data/lib/mk_stack/docs/mk_stack/mk_stack.001.png +0 -0
- data/lib/mk_stack/docs/mk_stack.key +0 -0
- data/lib/mk_stack/docs/readme.html +142 -0
- data/lib/mk_stack/docs/readme.org +55 -0
- data/lib/mk_stack/mk_stack.rb +126 -0
- data/lib/mk_stack/project.code-workspace +5 -0
- data/lib/split_pdf/docs/images/split_pdf.001.png +0 -0
- data/lib/split_pdf/docs/readme.html +153 -0
- data/lib/split_pdf/docs/readme.org +68 -0
- data/lib/split_pdf/docs/split_pdf.key +0 -0
- data/lib/split_pdf/split_pdf.rb +118 -0
- data/lib/voca_buil/check_log.yaml +37 -0
- data/lib/voca_buil/docs/readme.html +178 -0
- data/lib/voca_buil/docs/readme.org +58 -0
- data/lib/voca_buil/docs/voca_buil.key +0 -0
- data/lib/voca_buil/docs/voca_buil.pdf +0 -0
- data/lib/voca_buil/docs/voca_buil.png +0 -0
- data/lib/voca_buil/multi_check.rb +308 -0
- data/lib/voca_buil/word_log.yaml +14 -0
- metadata +38 -1
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'fileutils'
|
|
4
|
+
require 'optparse'
|
|
5
|
+
require 'date'
|
|
6
|
+
|
|
7
|
+
class MkStack
|
|
8
|
+
def initialize(argv)
|
|
9
|
+
@options = {}
|
|
10
|
+
OptionParser.new do |opts|
|
|
11
|
+
opts.banner = "Usage: hc stack [options]"
|
|
12
|
+
opts.on('-n NUMBER', '--number=NUMBER', 'Add ordinal number') { |num| @options[:number] = num }
|
|
13
|
+
opts.on('-d', '--dryrun', 'Dry run (do not move or create anything)') { @options[:dryrun] = true }
|
|
14
|
+
end.parse!(argv)
|
|
15
|
+
|
|
16
|
+
@root_name = argv[0]
|
|
17
|
+
@date = argv[1] || Date.today.strftime('%y%m%d')
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def ordinal(n)
|
|
21
|
+
abs_n = n.to_i.abs
|
|
22
|
+
if (11..13).include?(abs_n % 100)
|
|
23
|
+
"#{n}th"
|
|
24
|
+
else
|
|
25
|
+
case abs_n % 10
|
|
26
|
+
when 1; "#{n}st"
|
|
27
|
+
when 2; "#{n}nd"
|
|
28
|
+
when 3; "#{n}rd"
|
|
29
|
+
else "#{n}th"
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def pull_root_name(dir_name)
|
|
35
|
+
if dir_name =~ /^_stack_(.+)_(\d{6})$/
|
|
36
|
+
$1
|
|
37
|
+
else
|
|
38
|
+
dir_name
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def next_available_dir(root_name, date)
|
|
43
|
+
n = 1
|
|
44
|
+
if root_name =~ /^(\d+)(st|nd|rd|th)$/
|
|
45
|
+
n = $1.to_i
|
|
46
|
+
elsif root_name =~ /^(\d+)(st|nd|rd|th)_(.+)$/
|
|
47
|
+
n = $1.to_i
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
candidates = Dir.glob("_stack_*_*").select do |d|
|
|
51
|
+
d =~ /^_stack_(\d+)(st|nd|rd|th)_(\d{6})$/
|
|
52
|
+
end
|
|
53
|
+
if candidates.any?
|
|
54
|
+
ordinals = candidates.map do |d|
|
|
55
|
+
if d =~ /^_stack_(\d+)(st|nd|rd|th)_(\d{6})$/
|
|
56
|
+
$1.to_i
|
|
57
|
+
else
|
|
58
|
+
nil
|
|
59
|
+
end
|
|
60
|
+
end.compact
|
|
61
|
+
n = ordinals.max + 1
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
base_name = ordinal(n)
|
|
65
|
+
dir = "_stack_#{base_name}_#{date}"
|
|
66
|
+
[base_name, dir]
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def find_max_ordinal
|
|
70
|
+
candidates = Dir.glob("_stack_*_*").select { |d| d =~ /^_stack_(\d+)(st|nd|rd|th)_(\d{6})$/ }
|
|
71
|
+
ordinals = candidates.map do |d|
|
|
72
|
+
if d =~ /^_stack_(\d+)(st|nd|rd|th)_(\d{6})$/
|
|
73
|
+
$1.to_i
|
|
74
|
+
else
|
|
75
|
+
nil
|
|
76
|
+
end
|
|
77
|
+
end.compact
|
|
78
|
+
ordinals.any? ? ordinals.max : 0
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def ensure_root_name
|
|
82
|
+
if @root_name.nil? || @root_name.strip.empty?
|
|
83
|
+
max_num = find_max_ordinal
|
|
84
|
+
@root_name = max_num > 0 ? ordinal(max_num) : "1st"
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def create_dir(dir)
|
|
89
|
+
if @options[:dryrun]
|
|
90
|
+
puts "[Dry Run] Would create directory: #{dir}"
|
|
91
|
+
else
|
|
92
|
+
Dir.mkdir(dir) unless Dir.exist?(dir)
|
|
93
|
+
puts "Created directory: #{dir}"
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def move_entries(dir)
|
|
98
|
+
exclude = ['.', '..', dir, '.vscode', 'project.code-workspace']
|
|
99
|
+
entries = Dir.glob('*', File::FNM_DOTMATCH) - exclude
|
|
100
|
+
|
|
101
|
+
entries.each do |entry|
|
|
102
|
+
if @options[:dryrun]
|
|
103
|
+
puts "[Dry Run] Would move #{entry} to #{dir}"
|
|
104
|
+
else
|
|
105
|
+
FileUtils.mv(entry, dir, force: true)
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
if @options[:dryrun]
|
|
110
|
+
puts "[Dry Run] Would move all files and directories (including hidden) to #{dir}, except .vscode and project.code-workspace"
|
|
111
|
+
else
|
|
112
|
+
puts "Moved all files and directories (including hidden) to #{dir}, except .vscode and project.code-workspace"
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def run
|
|
117
|
+
ensure_root_name
|
|
118
|
+
@root_name, dir = next_available_dir(@root_name, @date)
|
|
119
|
+
create_dir(dir)
|
|
120
|
+
move_entries(dir)
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
if __FILE__ == $0
|
|
125
|
+
MkStack.new(ARGV).run
|
|
126
|
+
end
|
|
Binary file
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
|
3
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" lang="jp" xml:lang="jp">
|
|
5
|
+
<head>
|
|
6
|
+
<!-- 2026-01-06 Tue 16:17 -->
|
|
7
|
+
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
|
8
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
9
|
+
<title>split_pdf</title>
|
|
10
|
+
<meta name="author" content="Shigeto R. Nishitani" />
|
|
11
|
+
<meta name="generator" content="Org Mode" />
|
|
12
|
+
<link rel="stylesheet" type="text/css" href="https://fniessen.github.io/org-html-themes/src/readtheorg_theme/css/htmlize.css"/>
|
|
13
|
+
<link rel="stylesheet" type="text/css" href="https://fniessen.github.io/org-html-themes/src/readtheorg_theme/css/readtheorg.css"/>
|
|
14
|
+
<link rel="stylesheet" type="text/css" href="https://fniessen.github.io/org-html-themes/src/readtheorg_theme/css/code-copy.css"/>
|
|
15
|
+
<link rel="stylesheet" type="text/css" href="src/readtheorg_theme/css/search.css"/>
|
|
16
|
+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
|
|
17
|
+
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
|
|
18
|
+
<script type="text/javascript" src="https://fniessen.github.io/org-html-themes/src/lib/js/jquery.stickytableheaders.min.js"></script>
|
|
19
|
+
<script type="text/javascript" src="https://fniessen.github.io/org-html-themes/src/readtheorg_theme/js/search.js"></script>
|
|
20
|
+
<script type="text/javascript" src="https://fniessen.github.io/org-html-themes/src/readtheorg_theme/js/readtheorg.js"></script>
|
|
21
|
+
<script type="text/javascript" src="https://fniessen.github.io/org-html-themes/src/readtheorg_theme/js/code-copy.js"></script>
|
|
22
|
+
</head>
|
|
23
|
+
<body>
|
|
24
|
+
<div id="content" class="content">
|
|
25
|
+
<h1 class="title">split_pdf</h1>
|
|
26
|
+
<div id="table-of-contents" role="doc-toc">
|
|
27
|
+
<h2>Table of Contents</h2>
|
|
28
|
+
<div id="text-table-of-contents" role="doc-toc">
|
|
29
|
+
<ul>
|
|
30
|
+
<li><a href="#org974aec3">1. Name</a></li>
|
|
31
|
+
<li><a href="#org02bc359">2. Help</a></li>
|
|
32
|
+
<li><a href="#org9f0d630">3. Usage</a>
|
|
33
|
+
<ul>
|
|
34
|
+
<li><a href="#org37d7eb6">3.1. sample</a></li>
|
|
35
|
+
<li><a href="#org94b19df">3.2. split</a></li>
|
|
36
|
+
<li><a href="#org5a579db">3.3. then modify</a></li>
|
|
37
|
+
</ul>
|
|
38
|
+
</li>
|
|
39
|
+
</ul>
|
|
40
|
+
</div>
|
|
41
|
+
</div>
|
|
42
|
+
<div id="outline-container-org974aec3" class="outline-2">
|
|
43
|
+
<h2 id="org974aec3"><span class="section-number-2">1.</span> Name</h2>
|
|
44
|
+
<div class="outline-text-2" id="text-1">
|
|
45
|
+
<p>
|
|
46
|
+
split pdf using YAML
|
|
47
|
+
</p>
|
|
48
|
+
|
|
49
|
+
<p>
|
|
50
|
+
自炊したpdfを読みやすいようにdivideするツールです.
|
|
51
|
+
conquerしてください.
|
|
52
|
+
</p>
|
|
53
|
+
</div>
|
|
54
|
+
</div>
|
|
55
|
+
<div id="outline-container-org02bc359" class="outline-2">
|
|
56
|
+
<h2 id="org02bc359"><span class="section-number-2">2.</span> Help</h2>
|
|
57
|
+
<div class="outline-text-2" id="text-2">
|
|
58
|
+
<div class="org-src-container">
|
|
59
|
+
<pre class="src src-bash">> hc split_pdf -h
|
|
60
|
+
Usage: hc [options]
|
|
61
|
+
-d, --dir=[DIR] Target directory for mk_yaml (default: .)
|
|
62
|
+
-s, --split [YAML] Split pdf wo pages by YAML (default: hc_array.yaml)
|
|
63
|
+
-w, --split_with_pages [YAML] Split pdf with pages by YAML (default: hc_array.yaml)
|
|
64
|
+
-y, --yaml Output sample YAML
|
|
65
|
+
</pre>
|
|
66
|
+
</div>
|
|
67
|
+
</div>
|
|
68
|
+
</div>
|
|
69
|
+
<div id="outline-container-org9f0d630" class="outline-2">
|
|
70
|
+
<h2 id="org9f0d630"><span class="section-number-2">3.</span> Usage</h2>
|
|
71
|
+
<div class="outline-text-2" id="text-3">
|
|
72
|
+
</div>
|
|
73
|
+
<div id="outline-container-org37d7eb6" class="outline-3">
|
|
74
|
+
<h3 id="org37d7eb6"><span class="section-number-3">3.1.</span> sample</h3>
|
|
75
|
+
<div class="outline-text-3" id="text-3-1">
|
|
76
|
+
<div class="org-src-container">
|
|
77
|
+
<pre class="src src-bash">> hc split_pdf -y
|
|
78
|
+
---
|
|
79
|
+
:source_file: <span style="color: #8b7355;">"./linux_basic.pdf"</span>
|
|
80
|
+
:target_dir: <span style="color: #8b7355;">"./linux_basic"</span>
|
|
81
|
+
:toc:
|
|
82
|
+
- :no:
|
|
83
|
+
:init: 1
|
|
84
|
+
:fin:
|
|
85
|
+
:head: title
|
|
86
|
+
- :no: s1
|
|
87
|
+
:init: 2
|
|
88
|
+
:fin:
|
|
89
|
+
:head: command
|
|
90
|
+
- :no: s1
|
|
91
|
+
:init: 7
|
|
92
|
+
:fin: 7
|
|
93
|
+
:head: line_edit
|
|
94
|
+
Save yaml data<span style="color: #1c86ee;"> in</span> <span style="color: #8b7355;">'hc_array.yaml'</span>.
|
|
95
|
+
</pre>
|
|
96
|
+
</div>
|
|
97
|
+
</div>
|
|
98
|
+
</div>
|
|
99
|
+
<div id="outline-container-org94b19df" class="outline-3">
|
|
100
|
+
<h3 id="org94b19df"><span class="section-number-3">3.2.</span> split</h3>
|
|
101
|
+
<div class="outline-text-3" id="text-3-2">
|
|
102
|
+
<div class="org-src-container">
|
|
103
|
+
<pre class="src src-bash">> hc split_pdf -w
|
|
104
|
+
hc_array.yaml
|
|
105
|
+
qpdf /Users/bob/Documents/epub_books/たのしいRuby.pdf --pages . 1-8 -- ./happy_ruby/preface_1-8.pdf
|
|
106
|
+
qpdf /Users/bob/Documents/epub_books/たのしいRuby.pdf --pages . 9-20 -- ./happy_ruby/toc_9-20.pdf
|
|
107
|
+
qpdf /Users/bob/Documents/epub_books/たのしいRuby.pdf --pages . 21-22 -- ./happy_ruby/p1_Rubyをはじめよう_21-22.pdf
|
|
108
|
+
qpdf /Users/bob/Documents/epub_books/たのしいRuby.pdf --pages . 23-48 -- ./happy_ruby/c1_はじめてのRuby_23-48.pdf
|
|
109
|
+
qpdf /Users/bob/Documents/epub_books/
|
|
110
|
+
...
|
|
111
|
+
</pre>
|
|
112
|
+
</div>
|
|
113
|
+
</div>
|
|
114
|
+
</div>
|
|
115
|
+
<div id="outline-container-org5a579db" class="outline-3">
|
|
116
|
+
<h3 id="org5a579db"><span class="section-number-3">3.3.</span> then modify</h3>
|
|
117
|
+
<div class="outline-text-3" id="text-3-3">
|
|
118
|
+
<pre class="example">
|
|
119
|
+
> hc view
|
|
120
|
+
</pre>
|
|
121
|
+
|
|
122
|
+
<p>
|
|
123
|
+
を見ながら整理してください.
|
|
124
|
+
こんな感じがいいでしょうね.
|
|
125
|
+
</p>
|
|
126
|
+
|
|
127
|
+
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
<colgroup>
|
|
131
|
+
<col class="org-left" />
|
|
132
|
+
</colgroup>
|
|
133
|
+
<tbody>
|
|
134
|
+
<tr>
|
|
135
|
+
<td class="org-left"><img src="./images/split_pdf.001.png" alt="split_pdf.001.png" /></td>
|
|
136
|
+
</tr>
|
|
137
|
+
|
|
138
|
+
<tr>
|
|
139
|
+
<td class="org-left">編集後のview</td>
|
|
140
|
+
</tr>
|
|
141
|
+
</tbody>
|
|
142
|
+
</table>
|
|
143
|
+
</div>
|
|
144
|
+
</div>
|
|
145
|
+
</div>
|
|
146
|
+
</div>
|
|
147
|
+
<div id="postamble" class="status">
|
|
148
|
+
<p class="author">Author: Shigeto R. Nishitani</p>
|
|
149
|
+
<p class="date">Created: 2026-01-06 Tue 16:17</p>
|
|
150
|
+
<p class="validation"><a href="https://validator.w3.org/check?uri=referer">Validate</a></p>
|
|
151
|
+
</div>
|
|
152
|
+
</body>
|
|
153
|
+
</html>
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
#+OPTIONS: ^:{}
|
|
2
|
+
#+STARTUP: indent nolineimages overview num
|
|
3
|
+
#+TITLE: split_pdf
|
|
4
|
+
#+AUTHOR: Shigeto R. Nishitani
|
|
5
|
+
#+EMAIL: (concat "shigeto_nishitani@mac.com")
|
|
6
|
+
#+LANGUAGE: jp
|
|
7
|
+
#+OPTIONS: H:4 toc:t num:2
|
|
8
|
+
#+SETUPFILE: https://fniessen.github.io/org-html-themes/org/theme-readtheorg.setup
|
|
9
|
+
|
|
10
|
+
* Name
|
|
11
|
+
split pdf using YAML
|
|
12
|
+
|
|
13
|
+
自炊したpdfを読みやすいようにdivideするツールです.
|
|
14
|
+
conquerしてください.
|
|
15
|
+
|
|
16
|
+
* Help
|
|
17
|
+
#+begin_src bash
|
|
18
|
+
> hc split_pdf -h
|
|
19
|
+
Usage: hc [options]
|
|
20
|
+
-d, --dir=[DIR] Target directory for mk_yaml (default: .)
|
|
21
|
+
-s, --split [YAML] Split pdf wo pages by YAML (default: hc_array.yaml)
|
|
22
|
+
-w, --split_with_pages [YAML] Split pdf with pages by YAML (default: hc_array.yaml)
|
|
23
|
+
-y, --yaml Output sample YAML
|
|
24
|
+
#+end_src
|
|
25
|
+
|
|
26
|
+
* Usage
|
|
27
|
+
** sample
|
|
28
|
+
#+begin_src bash
|
|
29
|
+
> hc split_pdf -y
|
|
30
|
+
---
|
|
31
|
+
:source_file: "./linux_basic.pdf"
|
|
32
|
+
:target_dir: "./linux_basic"
|
|
33
|
+
:toc:
|
|
34
|
+
- :no:
|
|
35
|
+
:init: 1
|
|
36
|
+
:fin:
|
|
37
|
+
:head: title
|
|
38
|
+
- :no: s1
|
|
39
|
+
:init: 2
|
|
40
|
+
:fin:
|
|
41
|
+
:head: command
|
|
42
|
+
- :no: s1
|
|
43
|
+
:init: 7
|
|
44
|
+
:fin: 7
|
|
45
|
+
:head: line_edit
|
|
46
|
+
Save yaml data in 'hc_array.yaml'.
|
|
47
|
+
#+end_src
|
|
48
|
+
|
|
49
|
+
** split
|
|
50
|
+
#+begin_src bash
|
|
51
|
+
> hc split_pdf -w
|
|
52
|
+
hc_array.yaml
|
|
53
|
+
qpdf /Users/bob/Documents/epub_books/たのしいRuby.pdf --pages . 1-8 -- ./happy_ruby/preface_1-8.pdf
|
|
54
|
+
qpdf /Users/bob/Documents/epub_books/たのしいRuby.pdf --pages . 9-20 -- ./happy_ruby/toc_9-20.pdf
|
|
55
|
+
qpdf /Users/bob/Documents/epub_books/たのしいRuby.pdf --pages . 21-22 -- ./happy_ruby/p1_Rubyをはじめよう_21-22.pdf
|
|
56
|
+
qpdf /Users/bob/Documents/epub_books/たのしいRuby.pdf --pages . 23-48 -- ./happy_ruby/c1_はじめてのRuby_23-48.pdf
|
|
57
|
+
qpdf /Users/bob/Documents/epub_books/
|
|
58
|
+
...
|
|
59
|
+
#+end_src
|
|
60
|
+
|
|
61
|
+
** then modify
|
|
62
|
+
: > hc view
|
|
63
|
+
を見ながら整理してください.
|
|
64
|
+
こんな感じがいいでしょうね.
|
|
65
|
+
|
|
66
|
+
| [[./images/split_pdf.001.png]]
|
|
67
|
+
| 編集後のview
|
|
68
|
+
|
|
Binary file
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
require "colorize"
|
|
3
|
+
require 'yaml'
|
|
4
|
+
require 'fileutils'
|
|
5
|
+
require 'optparse'
|
|
6
|
+
|
|
7
|
+
class SplitPDF
|
|
8
|
+
def initialize(argv)
|
|
9
|
+
@options = {}
|
|
10
|
+
OptionParser.new do |opts|
|
|
11
|
+
opts.on('-d[DIR]', '--dir=[DIR]', 'Target directory for mk_yaml (default: .)') do |dir|
|
|
12
|
+
@options[:dir] = dir || '.'
|
|
13
|
+
@options[:action] = :dir
|
|
14
|
+
end
|
|
15
|
+
opts.on('-s [YAML]', '--split [YAML]', 'Split pdf wo pages by YAML (default: hc_array.yaml)') do |yaml|
|
|
16
|
+
@options[:yaml] = yaml || 'hc_array.yaml'
|
|
17
|
+
@options[:action] = :split_without_pages
|
|
18
|
+
end
|
|
19
|
+
opts.on('-w [YAML]', '--split_with_pages [YAML]', 'Split pdf with pages by YAML (default: hc_array.yaml)') do |yaml|
|
|
20
|
+
@options[:yaml] = yaml || 'hc_array.yaml'
|
|
21
|
+
@options[:action] = :split_with_pages
|
|
22
|
+
end
|
|
23
|
+
opts.on('-y', '--yaml', 'Output sample YAML') do
|
|
24
|
+
@options[:action] = :sample
|
|
25
|
+
end
|
|
26
|
+
end.parse!(argv)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def run
|
|
30
|
+
case @options[:action]
|
|
31
|
+
when :sample
|
|
32
|
+
puts_sample_yaml
|
|
33
|
+
when :dir
|
|
34
|
+
mk_yaml
|
|
35
|
+
when :split_without_pages
|
|
36
|
+
split_pdf(true) # option: pages_wo
|
|
37
|
+
when :split_with_pages
|
|
38
|
+
split_pdf(false)
|
|
39
|
+
else
|
|
40
|
+
# OptionParserがusageを表示するので何もしない
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# ディレクトリからyamlを作成
|
|
45
|
+
def mk_yaml(t_dir = nil, out_file = 'tmp.yaml')
|
|
46
|
+
t_dir ||= @options[:dir]
|
|
47
|
+
t_dir = '.' if t_dir.nil? || t_dir.empty?
|
|
48
|
+
puts t_dir
|
|
49
|
+
toc = []
|
|
50
|
+
Dir.glob(File.join(t_dir, '*')).each do |file|
|
|
51
|
+
data = File.basename(file, '.pdf').split('_')
|
|
52
|
+
pages = data[1].split('-')
|
|
53
|
+
new_data = {
|
|
54
|
+
no: data[0],
|
|
55
|
+
init: pages[0].to_i,
|
|
56
|
+
fin: pages[1].to_i,
|
|
57
|
+
head: data[2..-1].join("_")
|
|
58
|
+
}
|
|
59
|
+
toc << new_data
|
|
60
|
+
end
|
|
61
|
+
File.write(out_file, YAML.dump(toc))
|
|
62
|
+
puts "YAML written to #{out_file}"
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# yamlを元にPDFを分割
|
|
66
|
+
def split_pdf(pages_wo = true, yaml_file = nil)
|
|
67
|
+
yaml_file ||= @options[:yaml]
|
|
68
|
+
|
|
69
|
+
puts yaml_file
|
|
70
|
+
data = YAML.load(File.read(yaml_file))
|
|
71
|
+
source_file = data[:source_file]
|
|
72
|
+
target_dir = data[:target_dir]
|
|
73
|
+
FileUtils.mkdir_p target_dir unless Dir.exist? target_dir
|
|
74
|
+
data[:toc].each do |v|
|
|
75
|
+
init = v[:init]
|
|
76
|
+
fin = v[:fin]
|
|
77
|
+
pages = if fin.nil?
|
|
78
|
+
fin = init
|
|
79
|
+
"#{init}"
|
|
80
|
+
else
|
|
81
|
+
"#{init}-#{fin}"
|
|
82
|
+
end
|
|
83
|
+
if pages_wo
|
|
84
|
+
o_file = [v[:no], v[:head]].compact.join('_') + ".pdf"
|
|
85
|
+
else
|
|
86
|
+
o_file = [v[:no], v[:head], pages].compact.join('_') + ".pdf"
|
|
87
|
+
end
|
|
88
|
+
target = File.join(target_dir, o_file)
|
|
89
|
+
comm = "qpdf #{source_file} --pages . #{init}-#{fin} -- #{target}"
|
|
90
|
+
puts comm
|
|
91
|
+
system(comm)
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# サンプルyamlを出力
|
|
96
|
+
def puts_sample_yaml(t_file = 'hc_array.yaml')
|
|
97
|
+
# ファイルが存在する場合は新しいファイル名にする
|
|
98
|
+
if File.exist?(t_file)
|
|
99
|
+
t_file = 'hc_array_new.yaml'
|
|
100
|
+
end
|
|
101
|
+
hc_array = {
|
|
102
|
+
source_file: './linux_basic.pdf',
|
|
103
|
+
target_dir: './linux_basic',
|
|
104
|
+
toc: [
|
|
105
|
+
{ no: nil, init: 1, fin: nil, head: 'title' },
|
|
106
|
+
{ no: 's1', init: 2, fin: nil, head: 'command' },
|
|
107
|
+
{ no: 's1', init: 7, fin: 7, head: 'line_edit' }
|
|
108
|
+
]
|
|
109
|
+
}
|
|
110
|
+
puts YAML.dump(hc_array)
|
|
111
|
+
File.write(t_file, YAML.dump(hc_array))
|
|
112
|
+
puts "Save yaml data in '#{t_file}'."
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
if __FILE__ == $0
|
|
117
|
+
SplitPDF.new(ARGV).run
|
|
118
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
---
|
|
2
|
+
- 2026-01-04 12:41:12.176173000 +09:00
|
|
3
|
+
- 2026-01-04 12:41:23.284421000 +09:00
|
|
4
|
+
- 2026-01-04 12:41:32.332028000 +09:00
|
|
5
|
+
- 2026-01-04 12:41:36.681559000 +09:00
|
|
6
|
+
- 2026-01-04 12:41:41.191036000 +09:00
|
|
7
|
+
- 2026-01-04 12:41:45.426982000 +09:00
|
|
8
|
+
- 2026-01-04 12:41:49.801718000 +09:00
|
|
9
|
+
- 2026-01-04 12:41:56.234857000 +09:00
|
|
10
|
+
- 2026-01-04 12:41:59.843909000 +09:00
|
|
11
|
+
- 2026-01-04 12:42:02.371171000 +09:00
|
|
12
|
+
- 2026-01-04 12:43:23.943653000 +09:00
|
|
13
|
+
- 2026-01-04 12:43:26.401539000 +09:00
|
|
14
|
+
- 2026-01-04 12:43:28.382194000 +09:00
|
|
15
|
+
- 2026-01-04 12:43:30.707110000 +09:00
|
|
16
|
+
- 2026-01-04 12:43:32.802320000 +09:00
|
|
17
|
+
- 2026-01-04 12:43:34.921912000 +09:00
|
|
18
|
+
- 2026-01-04 12:43:36.843520000 +09:00
|
|
19
|
+
- 2026-01-04 12:43:38.798417000 +09:00
|
|
20
|
+
- 2026-01-04 12:43:40.765974000 +09:00
|
|
21
|
+
- 2026-01-04 12:43:42.612879000 +09:00
|
|
22
|
+
- 2026-01-04 12:43:44.779400000 +09:00
|
|
23
|
+
- 2026-01-04 12:44:21.570235000 +09:00
|
|
24
|
+
- 2026-01-04 12:44:56.512753000 +09:00
|
|
25
|
+
- 2026-01-04 12:45:04.304045000 +09:00
|
|
26
|
+
- 2026-01-04 12:45:09.074071000 +09:00
|
|
27
|
+
- 2026-01-04 12:45:11.735977000 +09:00
|
|
28
|
+
- 2026-01-04 12:45:14.592539000 +09:00
|
|
29
|
+
- 2026-01-04 12:45:17.229176000 +09:00
|
|
30
|
+
- 2026-01-05 10:50:24.486043000 +09:00
|
|
31
|
+
- 2026-01-05 10:50:28.730545000 +09:00
|
|
32
|
+
- 2026-01-05 10:50:33.776214000 +09:00
|
|
33
|
+
- 2026-01-05 10:50:34.898283000 +09:00
|
|
34
|
+
- 2026-01-05 10:50:35.317665000 +09:00
|
|
35
|
+
- 2026-01-05 10:50:35.734562000 +09:00
|
|
36
|
+
- 2026-01-05 10:50:36.919961000 +09:00
|
|
37
|
+
- 2026-01-06 12:10:41.586854000 +09:00
|