Class: Metanorma::Utils::LineStatus

Inherits:
Object
  • Object
show all
Defined in:
lib/utils/linestatus.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLineStatus

Returns a new instance of LineStatus.



17
18
19
20
21
22
23
# File 'lib/utils/linestatus.rb', line 17

def initialize
  # process as passthrough: init = true until hit end of document header
  @pass = true
  @delim = false
  @pass_delim = false
  @delimln = ""
end

Instance Attribute Details

#delimlnObject (readonly)

block delimiter for preformatted text, e.g. ====



9
10
11
# File 'lib/utils/linestatus.rb', line 9

def delimln
  @delimln
end

#is_delimObject (readonly)

block attribute associated with preformatted text, e.g. [source]



7
8
9
# File 'lib/utils/linestatus.rb', line 7

def is_delim
  @is_delim
end

#middoc_docattrObject (readonly)

document attribute in the middle of a document, not in a header



5
6
7
# File 'lib/utils/linestatus.rb', line 5

def middoc_docattr
  @middoc_docattr
end

#passObject (readonly)

passthrough block



13
14
15
# File 'lib/utils/linestatus.rb', line 13

def pass
  @pass
end

#pass_delimObject (readonly)

passthrough block delimiter



11
12
13
# File 'lib/utils/linestatus.rb', line 11

def pass_delim
  @pass_delim
end

#prev_lineObject (readonly)

record previous line read



15
16
17
# File 'lib/utils/linestatus.rb', line 15

def prev_line
  @prev_line
end

Instance Method Details

#process(line) ⇒ Object



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
# File 'lib/utils/linestatus.rb', line 25

def process(line)
  text = line.rstrip
  text == "++++" && !@delimln and @pass = !@pass
  if @middoc_docattr && !/^:[^ :]+:($| )/.match?(text)
    @middoc_docattr = false
    @pass = false
  elsif (@is_delim && /^(--+|\*\*+|==+|__+)$/.match?(text)) ||
      (!@is_delim && !@delimln && /^-----*$|^\.\.\.\.\.*$|^\/\/\/\/\/*$/
    .match?(text))
    @delimln = text
    @pass = true
  elsif @pass_delim
    @pass = true
    @delimln = "" # end of paragraph for paragraph with [pass]
  elsif @delimln && text == @delimln
    @pass = false
    @delimln = nil
  elsif /^:[^ :]+:($| )/.match?(text) &&
      (@prev_line.empty? || @middoc_docattr)
    @pass = true
    @middoc_docattr = true
  end
  @is_delim = /^\[(source|listing|literal|pass|comment)\b/.match?(text)
  @pass_delim = /^\[(pass)\b/.match?(text)
  @prev_line = text.strip
end