Class: ReVIEW::Book::Chapter
Instance Attribute Summary collapse
Attributes included from Compilable
#content, #path
Instance Method Summary
collapse
Methods included from Compilable
#basename, #bibpaper, #bibpaper_index, #column, #column_index, #dirname, #equation, #equation_index, #footnote, #footnote_index, #headline, #headline_index, #icon_index, #image, #image_index, #indepimage_index, #lines, #list, #list_index, #name, #next_chapter, #numberless_image_index, #prev_chapter, #size, #table, #table_index, #title, #volume
Methods included from TextUtils
#detab, #split_paragraph
Constructor Details
#initialize(book, number, name, path, io = nil) ⇒ Chapter
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
|
# File 'lib/review/book/chapter.rb', line 21
def initialize(book, number, name, path, io = nil)
@book = book
@number = number
@name = name
@path = path
@io = io
@title = nil
if @io
begin
@content = @io.read
rescue
@content = nil
end
else
@content = nil
end
if !@content && @path && File.exist?(@path)
@content = File.read(@path, mode: 'r:BOM|utf-8')
@number = nil if %w[nonum nodisp notoc].include?()
end
@list_index = nil
@table_index = nil
@equation_index = nil
= nil
@image_index = nil
@icon_index = nil
@numberless_image_index = nil
@indepimage_index = nil
@headline_index = nil
@column_index = nil
@volume = nil
end
|
Instance Attribute Details
Returns the value of attribute book.
19
20
21
|
# File 'lib/review/book/chapter.rb', line 19
def book
@book
end
|
Returns the value of attribute number.
19
20
21
|
# File 'lib/review/book/chapter.rb', line 19
def number
@number
end
|
Instance Method Details
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/review/book/chapter.rb', line 54
def
f = LineInput.new(StringIO.new(@content))
while f.next?
case f.peek
when /\A=+[\[\s\{]/
m = /\A(=+)(?:\[(.+?)\])?(?:\{(.+?)\})?(.*)/.match(f.gets)
return m[2]
when %r{/\A//[a-z]+/}
line = f.gets
if line.rstrip[-1, 1] == '{'
f.until_match(%r{\A//\}})
end
end
f.gets
end
nil
end
|
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
# File 'lib/review/book/chapter.rb', line 76
def format_number(heading = true)
return '' unless @number
if on_predef?
return @number.to_s
end
if on_appendix?
if @number < 1 || @number > 27
return @number.to_s
end
if @book.config['appendix_format']
raise ReVIEW::ConfigError, %Q('appendix_format:' in config.yml is obsoleted.)
end
i18n_appendix = I18n.get('appendix')
fmt = i18n_appendix.scan(/%\w{1,3}/).first || '%s'
I18n.update('appendix_without_heading' => fmt)
if heading
return I18n.t('appendix', @number)
else
return I18n.t('appendix_without_heading', @number)
end
end
if heading
I18n.t('chapter', @number)
else
@number.to_s
end
end
|
72
73
74
|
# File 'lib/review/book/chapter.rb', line 72
def inspect
"#<#{self.class} #{@number} #{@path}>"
end
|
#on_appendix? ⇒ Boolean
Also known as:
on_APPENDIX?
117
118
119
|
# File 'lib/review/book/chapter.rb', line 117
def on_appendix?
on_file?(@book.read_appendix)
end
|
#on_chaps? ⇒ Boolean
Also known as:
on_CHAPS?
109
110
111
|
# File 'lib/review/book/chapter.rb', line 109
def on_chaps?
on_file?(@book.read_chaps)
end
|
#on_postdef? ⇒ Boolean
Also known as:
on_POSTDEF?
121
122
123
|
# File 'lib/review/book/chapter.rb', line 121
def on_postdef?
on_file?(@book.read_postdef)
end
|
#on_predef? ⇒ Boolean
Also known as:
on_PREDEF?
113
114
115
|
# File 'lib/review/book/chapter.rb', line 113
def on_predef?
on_file?(@book.read_predef)
end
|