Class: QED::Parser::TextSection

Inherits:
Section
  • Object
show all
Defined in:
lib/qed/parser.rb

Instance Attribute Summary collapse

Attributes inherited from Section

#line, #text

Instance Method Summary collapse

Constructor Details

#initialize(text, line, *args) ⇒ TextSection

Returns a new instance of TextSection.



90
91
92
93
94
95
# File 'lib/qed/parser.rb', line 90

def initialize(text, line, *args)
  @text = text
  @line = line
  @args = args
  @cont = []
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



88
89
90
# File 'lib/qed/parser.rb', line 88

def args
  @args
end

#contObject (readonly)

Returns the value of attribute cont.



89
90
91
# File 'lib/qed/parser.rb', line 89

def cont
  @cont
end

Instance Method Details

#<<(text) ⇒ Object



96
97
98
99
# File 'lib/qed/parser.rb', line 96

def <<(text)
  @cont << clean_continuation(text)
  @args << block_continuation(text)
end

#block_continuation(text) ⇒ Object

Block the text, removing white lines, triple quote brackets and indention.



121
122
123
124
125
126
127
# File 'lib/qed/parser.rb', line 121

def block_continuation(text)
  text = text.tabto(0).chomp.sub(/\A\n/,'')
  if md = /\A["]{3,}(.*?)["]{3,}\Z/.match(text)
    text = md[1]
  end
  text.rstrip
end

#clean_continuation(text) ⇒ Object

Clean up the text, removing unccesseary white lines and triple quote brackets, but keep indention intact.



111
112
113
114
115
116
117
# File 'lib/qed/parser.rb', line 111

def clean_continuation(text)
  text = text.chomp.sub(/\A\n/,'')
  if md = /\A["]{3,}(.*?)["]{3,}\Z/.match(text)
    text = md[1]
  end
  text.rstrip
end

#raw?Boolean

TODO: Use ‘:’ or ‘…’ ?

Returns:

  • (Boolean)


104
105
106
107
# File 'lib/qed/parser.rb', line 104

def raw?
  #/\:\s*\Z/m =~ text
  /\.\.\.\s*\Z/m =~ text
end

#typeObject



100
101
102
# File 'lib/qed/parser.rb', line 100

def type
  :text
end