-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodes_list.rb
60 lines (55 loc) · 1.66 KB
/
codes_list.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# frozen_string_literal: true
require 'date'
require 'fileutils'
list_targets = {
'app_develop_loadmap.adoc' => 'chap01',
'app_tech_research.adoc' => 'chap02',
'dev_cmd_line_app.adoc' => 'chap03',
'web_app_tech_research_sub.adoc' => 'chap04',
'dev_web_app.adoc' => 'chap05',
'dev_excel_app.adoc' => 'chap06',
'setup_ruby_env.adoc' => 'appendix-c',
'ruby_basics.adoc' => 'appendix-d',
'column08.adoc' => 'column08',
}
date = Date.today.strftime("%Y%m%d")
dir_name = "rubybook3-samples-#{date}"
Dir.mkdir(dir_name)
zip_name = dir_name + '.zip'
list_targets.each do |adoc, chap|
File.open(adoc, 'r') do |f|
source_files = []
puts "#{adoc}, #{chap} ----------"
sub_dir_name = "#{dir_name}/#{chap}"
Dir.mkdir(sub_dir_name)
f.each do |line|
# if line =~ /include::(.+adoc)/
# puts line
# end
if line =~ %r{include::\{sourcesdir\}/(.+)\[.*\]}
source_files << $1
end
end
if chap == 'chap05'
source_files.concat(['webapp/collect.erb', 'webapp/delete.erb', 'webapp/index.html',
'webapp/list.erb', 'webapp/nodeleted.erb', 'webapp/report.erb'])
end
files = source_files.uniq.sort
files.each do |f3|
from = 'codes/' + f3
f3_2 = f3.split('/')
if f3_2.size > 1
sub_sub_dir_name = sub_dir_name + '/' + f3_2.first
Dir.mkdir(sub_sub_dir_name) unless Dir.exist?(sub_sub_dir_name)
end
to = sub_dir_name + '/' + f3
puts "from: #{from}, to: #{to}"
# File.open(from, 'r') do |f4|
# File.open(to, 'w') do |f5|
FileUtils.copy(from, to)
# end
# end
end
end
end
system "zip -r #{zip_name} #{dir_name}"