Class: Metanorma::Utils::LineStatus
- Inherits:
-
Object
- Object
- Metanorma::Utils::LineStatus
- Defined in:
- lib/utils/linestatus.rb
Instance Attribute Summary collapse
-
#delimln ⇒ Object
readonly
block delimiter for preformatted text, e.g.
-
#is_delim ⇒ Object
readonly
block attribute associated with preformatted text, e.g.
-
#middoc_docattr ⇒ Object
readonly
document attribute in the middle of a document, not in a header.
-
#pass ⇒ Object
readonly
passthrough block.
-
#pass_delim ⇒ Object
readonly
passthrough block delimiter.
-
#prev_line ⇒ Object
readonly
record previous line read.
Instance Method Summary collapse
-
#initialize ⇒ LineStatus
constructor
A new instance of LineStatus.
- #process(line) ⇒ Object
Constructor Details
#initialize ⇒ LineStatus
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
#delimln ⇒ Object (readonly)
block delimiter for preformatted text, e.g. ====
9 10 11 |
# File 'lib/utils/linestatus.rb', line 9 def delimln @delimln end |
#is_delim ⇒ Object (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_docattr ⇒ Object (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 |
#pass ⇒ Object (readonly)
passthrough block
13 14 15 |
# File 'lib/utils/linestatus.rb', line 13 def pass @pass end |
#pass_delim ⇒ Object (readonly)
passthrough block delimiter
11 12 13 |
# File 'lib/utils/linestatus.rb', line 11 def pass_delim @pass_delim end |
#prev_line ⇒ Object (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 |