xpub 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,70 +1,65 @@
1
+ # Xpub module
1
2
  module Xpub
2
- class CallBook
3
- class CallChecker
4
-
5
- def initialize name, book
6
- @name = name
7
- @book = book
8
- end
3
+ class CallBook
4
+ class CallChecker
5
+ def initialize(name, book)
6
+ @name = name
7
+ @book = book
8
+ end
9
+
10
+ def validate
11
+ end
9
12
 
10
- def validate
11
- end
13
+ def _check(_option, pattern)
14
+ words = {}
15
+ @book.src_files.each do |file|
16
+ f = open file.full_path
17
+ f.each_with_index do |line, index|
18
+ line.match(pattern) do |md|
19
+ if words[md[1]]
20
+ words[md[1]] << { file: file.file, line: (index + 1) }
21
+ else
22
+ words[md[1]] = [{ file: file.file, line: (index + 1) }]
23
+ end
24
+ end
25
+ end
26
+ f.close
27
+ end
12
28
 
13
- def _check option, pattern
14
- words = {}
15
- @book.src_files.each do |file|
16
- f = open file.full_path
17
- f.each_with_index do |line, index|
18
- line.match(pattern) do |md|
19
- if words[md[1]]
20
- words[md[1]] << { :file => file.file, :line => (index + 1) }
21
- else
22
- words[md[1]] = [{ :file => file.file, :line => (index + 1) }]
23
- end
29
+ words.sort.each do |word, infos|
30
+ next unless word
31
+ puts word.color :red
32
+ infos.each do |info|
33
+ puts " #{info[:file]}(#{info[:line]})"
34
+ end
35
+ end
24
36
  end
25
- end
26
- f.close
27
37
  end
28
38
 
29
- words.sort.each do |word, infos|
30
- if word
31
- puts word.color :red
32
- infos.each { |info|
33
- puts " #{info[:file]}(#{info[:line]})"
34
- }
35
- end
39
+ class CallNumberChecker < CallChecker
40
+ def check(option)
41
+ _check option, /([0-9一二三四五六七八九十百千万億兆京〇零]+)/
42
+ end
36
43
  end
37
- end
38
- end
39
-
40
- class CallNumberChecker < CallChecker
41
- def check option
42
- _check option, /([0-9一二三四五六七八九十百千万億兆京〇零]+)/
43
- end
44
- end
45
44
 
46
- class CallKanaChecker < CallChecker
47
- def check option
48
- _check option, /([\p{Katakana}ー-]+)/
49
- end
50
- end
45
+ class CallKanaChecker < CallChecker
46
+ def check(option)
47
+ _check option, /([\p{Katakana}ー-]+)/
48
+ end
49
+ end
51
50
 
52
- def number_checker name, &block
53
- call = CallNumberChecker.new name, self
54
- if block
55
- call.instance_eval &block
56
- end
57
- call.validate
58
- @checkers << call
59
- end
51
+ def number_checker(name, &block)
52
+ call = CallNumberChecker.new name, self
53
+ call.instance_eval(&block) if block
54
+ call.validate
55
+ @checkers << call
56
+ end
60
57
 
61
- def kana_checker name, &block
62
- call = CallKanaChecker.new name, self
63
- if block
64
- call.instance_eval &block
65
- end
66
- call.validate
67
- @checkers << call
58
+ def kana_checker(name, &block)
59
+ call = CallKanaChecker.new name, self
60
+ call.instance_eval(&block) if block
61
+ call.validate
62
+ @checkers << call
63
+ end
68
64
  end
69
- end
70
65
  end
@@ -1,36 +1,36 @@
1
+ # Xpub module
1
2
  module Xpub
2
- class CallBook
3
- class CallLatexBuilder
4
- class CallLatexOp
3
+ class CallBook
4
+ class CallLatexBuilder
5
+ class CallLatexOp
6
+ def initialize(name, book, builder)
7
+ @name = name
8
+ @book = book
9
+ @builder = builder
10
+ end
5
11
 
6
- def initialize name, book, builder
7
- @name = name
8
- @book = book
9
- @builder = builder
10
- end
11
- def validate
12
- end
12
+ def validate
13
+ end
13
14
 
14
- def template_path
15
- "#{Dir::getwd}/theme/#{@builder.theme}/#{@name}/#{@metadata}.erb"
16
- end
15
+ def template_path
16
+ "#{Dir.getwd}/theme/#{@builder.theme}/#{@name}/#{@metadata}.erb"
17
+ end
17
18
 
18
- def latex book, builder
19
- f = open template_path
20
- erb = ERB.new f.read, nil, "-"
21
- f.close
22
- erb.result(binding)
23
- end
19
+ def latex(book, builder)
20
+ f = open template_path
21
+ erb = ERB.new f.read, nil, '-'
22
+ f.close
23
+ erb.result(binding)
24
+ end
25
+ end
24
26
 
25
- end
27
+ class CallImgPageLatexOp < CallLatexOp
28
+ dsl_accessor :topoffset, default: '0in'
29
+ dsl_accessor :leftoffset, default: '0in'
30
+ dsl_accessor :file
26
31
 
27
- class CallImgPageLatexOp < CallLatexOp
28
- dsl_accessor :topoffset, :default => "0in"
29
- dsl_accessor :leftoffset, :default => "0in"
30
- dsl_accessor :file
31
-
32
- def latex book, builder
33
- <<"EOS"
32
+ def latex(_book, _builder)
33
+ <<"EOS"
34
34
  \\enlargethispage{200truemm}%
35
35
  \\thispagestyle{empty}%
36
36
  \\vspace*{-1truein}
@@ -41,20 +41,20 @@ module Xpub
41
41
  \\includegraphics[width=\\paperheight,height=\\paperwidth]{#{file}}
42
42
  \\clearpage\n
43
43
  EOS
44
- end
45
- end
44
+ end
45
+ end
46
46
 
47
- class CallEmptyPageLatexOp < CallLatexOp
48
- dsl_accessor :no_page_number, :default => false
47
+ class CallEmptyPageLatexOp < CallLatexOp
48
+ dsl_accessor :no_page_number, default: false
49
49
 
50
- def latex book, builder
51
- (no_page_number ? "\\thispagestyle{empty}" : "") + " \\clearpage\n"
52
- end
53
- end
50
+ def latex(_book, _builder)
51
+ (no_page_number ? '\\thispagestyle{empty}' : '') + " \\clearpage\n"
52
+ end
53
+ end
54
54
 
55
- class CallInnerTitlePageLatexOp < CallLatexOp
56
- def latex book, builder
57
- <<"EOS"
55
+ class CallInnerTitlePageLatexOp < CallLatexOp
56
+ def latex(book, _builder)
57
+ <<"EOS"
58
58
  \\makeatletter
59
59
  {
60
60
  \\thispagestyle{empty}%
@@ -71,7 +71,7 @@ EOS
71
71
  \\end{center}
72
72
  \\vspace*{1.5cm}
73
73
  \\begin{center}
74
- {\\Large #{book.creators.map { |c| c.name }.join " "}}
74
+ {\\Large #{book.creators.map(&:name).join ' '}}
75
75
  \\end{center}
76
76
  \\vspace*{1.5cm}
77
77
  \\begin{flushleft}
@@ -82,54 +82,43 @@ EOS
82
82
  }%
83
83
  \\makeatother
84
84
  EOS
85
- end
86
- end
85
+ end
86
+ end
87
87
 
88
- def hyoushi_image_page name, &block
89
- call = CallImgPageLatexOp.new name, @book, self
90
- if block
91
- call.instance_eval &block
92
- end
93
- call.validate
94
- @hyoushi << call
95
- end
88
+ def hyoushi_image_page(name, &block)
89
+ call = CallImgPageLatexOp.new name, @book, self
90
+ call.instance_eval(&block) if block
91
+ call.validate
92
+ @hyoushi << call
93
+ end
96
94
 
97
- def hyoushi_empty_page name, &block
98
- call = CallEmptyPageLatexOp.new name, @book, self
99
- if block
100
- call.instance_eval &block
101
- end
102
- call.validate
103
- @hyoushi << call
104
- end
95
+ def hyoushi_empty_page(name, &block)
96
+ call = CallEmptyPageLatexOp.new name, @book, self
97
+ call.instance_eval(&block) if block
98
+ call.validate
99
+ @hyoushi << call
100
+ end
105
101
 
106
- def hyoushi_inner_title_page name, &block
107
- call = CallInnerTitlePageLatexOp.new name, @book, self
108
- if block
109
- call.instance_eval &block
110
- end
111
- call.validate
112
- @hyoushi << call
113
- end
102
+ def hyoushi_inner_title_page(name, &block)
103
+ call = CallInnerTitlePageLatexOp.new name, @book, self
104
+ call.instance_eval(&block) if block
105
+ call.validate
106
+ @hyoushi << call
107
+ end
114
108
 
115
- def urahyoushi_image_page name, &block
116
- call = CallImgPageLatexOp.new name, @book, self
117
- if block
118
- call.instance_eval &block
119
- end
120
- call.validate
121
- @urahyoushi << call
122
- end
109
+ def urahyoushi_image_page(name, &block)
110
+ call = CallImgPageLatexOp.new name, @book, self
111
+ call.instance_eval(&block) if block
112
+ call.validate
113
+ @urahyoushi << call
114
+ end
123
115
 
124
- def urahyoushi_empty_page name, &block
125
- call = CallEmptyPageLatexOp.new name, @book, self
126
- if block
127
- call.instance_eval &block
116
+ def urahyoushi_empty_page(name, &block)
117
+ call = CallEmptyPageLatexOp.new name, @book, self
118
+ call.instance_eval(&block) if block
119
+ call.validate
120
+ @urahyoushi << call
121
+ end
128
122
  end
129
- call.validate
130
- @urahyoushi << call
131
- end
132
-
133
123
  end
134
- end
135
124
  end
@@ -1,139 +1,119 @@
1
1
  module Xpub
2
- class CallBook
2
+ class CallBook
3
+ class CallSrcFile
4
+ attr_reader :file
3
5
 
4
- class CallSrcFile
5
- attr_reader :file
6
+ def initialize(file)
7
+ @file = file
8
+ end
6
9
 
7
- def initialize file
8
- @file = file
9
- end
10
+ def full_path
11
+ "#{Dir.getwd}/src/#{@file}"
12
+ end
10
13
 
11
- def full_path
12
- "#{Dir::getwd}/src/#{@file}"
13
- end
14
+ def validate
15
+ raise "File does not exist.#{full_path}" unless File.exist? full_path
16
+ end
14
17
 
15
- def validate
16
- if !File.exist? full_path
17
- raise "File does not exist.#{full_path}"
18
+ def debug
19
+ p full_path
20
+ end
18
21
  end
19
- end
20
22
 
21
- def debug
22
- p full_path
23
- end
24
- end
25
-
26
- class CallMdFile < CallSrcFile
27
- def initialize file
28
- if !file.match "\.md$"
29
- file = file + ".md"
23
+ class CallMdFile < CallSrcFile
24
+ def initialize(file)
25
+ file += '.md' unless file =~ /.md$/
26
+ super file
27
+ end
30
28
  end
31
- super file
32
- end
33
- end
34
29
 
35
- class CallImgFile < CallSrcFile
36
- def validate
37
- super
38
- if !@file.match "\.(jpeg|jpg|png|bmp|pdf)$"
39
- raise "Image File Ext is not Image Ext. #{@file}"
30
+ class CallImgFile < CallSrcFile
31
+ def validate
32
+ super
33
+ raise "Image File Ext is not Image Ext. #{@file}" unless @file =~ /.(jpeg|jpg|png|bmp|pdf)$/
34
+ end
40
35
  end
41
- end
42
- end
43
-
44
36
 
45
- class CallImgFiles
46
- attr_reader :dir
47
-
48
- def initialize dir
49
- @dir = dir
50
- end
51
-
52
- def full_path
53
- "#{Dir::getwd}/src/#{@dir}"
54
- end
55
-
56
- def validate
57
- if !Dir.exist? full_path
58
- raise "Image Dir does not exist.#{full_path}"
37
+ class CallImgFiles
38
+ attr_reader :dir
39
+
40
+ def initialize(dir)
41
+ @dir = dir
42
+ end
43
+
44
+ def full_path
45
+ "#{Dir.getwd}/src/#{@dir}"
46
+ end
47
+
48
+ def validate
49
+ raise "Image Dir does not exist.#{full_path}" unless Dir.exist? full_path
50
+ end
51
+
52
+ def img_files
53
+ validate
54
+ Dir.glob("#{full_path}/**/*.{jpeg,jpg,png,bmp,pdf}").sort.map do |path|
55
+ img = CallImgFile.new path.sub(full_path + '/', '')
56
+ img.validate
57
+ img
58
+ end
59
+ end
59
60
  end
60
- end
61
-
62
- def img_files
63
- validate
64
- Dir.glob("#{full_path}/**/*.{jpeg,jpg,png,bmp,pdf}").sort.map { |path|
65
- img = CallImgFile.new path.sub(full_path + "/", "")
66
- img.validate
67
- img
68
- }
69
- end
70
- end
71
-
72
- class CallMdFiles
73
- attr_reader :dir
74
61
 
75
- def initialize dir
76
- @dir = dir
77
- end
78
-
79
- def full_path
80
- "#{Dir::getwd}/src/#{@dir}"
81
- end
82
-
83
- def validate
84
- if !Dir.exist? full_path
85
- raise "Markdown Dir does not exist.#{full_path}"
62
+ class CallMdFiles
63
+ attr_reader :dir
64
+
65
+ def initialize(dir)
66
+ @dir = dir
67
+ end
68
+
69
+ def full_path
70
+ "#{Dir.getwd}/src/#{@dir}"
71
+ end
72
+
73
+ def validate
74
+ raise "Markdown Dir does not exist.#{full_path}" unless Dir.exist? full_path
75
+ end
76
+
77
+ def md_files
78
+ validate
79
+ Dir.glob("#{full_path}/**/*.md").sort.map do |path|
80
+ mf = CallMdFile.new path.sub("#{Dir.getwd}/src/", '')
81
+ mf.validate
82
+ mf
83
+ end
84
+ end
85
+
86
+ def debug
87
+ p full_path
88
+ end
86
89
  end
87
- end
88
-
89
- def md_files
90
- validate
91
- Dir.glob("#{full_path}/**/*.md").sort.map { |path|
92
- mf = CallMdFile.new path.sub("#{Dir::getwd}/src/", "")
93
- mf.validate
94
- mf
95
- }
96
- end
97
-
98
- def debug
99
- p full_path
100
- end
101
- end
102
90
 
103
- def md_file file, &block
104
- call = CallMdFile.new file
105
- if block
106
- call.instance_eval &block
107
- end
108
- call.validate
109
- @src_files << call
110
- end
91
+ def md_file(file, &block)
92
+ call = CallMdFile.new file
93
+ call.instance_eval(&block) if block
94
+ call.validate
95
+ @src_files << call
96
+ end
111
97
 
112
- def md_files dir, &block
113
- call = CallMdFiles.new dir
114
- if block
115
- call.instance_eval &block
116
- end
117
- call.validate
118
- @src_files.concat call.md_files
119
- end
98
+ def md_files(dir, &block)
99
+ call = CallMdFiles.new dir
100
+ call.instance_eval(&block) if block
101
+ call.validate
102
+ @src_files.concat call.md_files
103
+ end
120
104
 
121
- def img_file file, &block
122
- call = CallImgFile.new file
123
- if block
124
- call.instance_eval &block
125
- end
126
- call.validate
127
- @resource_files << call
128
- end
105
+ def img_file(file, &block)
106
+ call = CallImgFile.new file
107
+ call.instance_eval(&block) if block
108
+ call.validate
109
+ @resource_files << call
110
+ end
129
111
 
130
- def img_files dir, &block
131
- call = CallImgFiles.new dir
132
- if block
133
- call.instance_eval &block
134
- end
135
- call.validate
136
- @resource_files.concat call.img_files
112
+ def img_files(dir, &block)
113
+ call = CallImgFiles.new dir
114
+ call.instance_eval(&block) if block
115
+ call.validate
116
+ @resource_files.concat call.img_files
117
+ end
137
118
  end
138
- end
139
119
  end