Class: QED::Parser::Block
Overview
Section Block
Instance Attribute Summary collapse
-
#back_step ⇒ Object
readonly
previous block.
-
#next_step ⇒ Object
readonly
next block.
-
#raw ⇒ Object
readonly
Block raw code/text.
Instance Method Summary collapse
-
#arguments ⇒ Object
Returns an Array of prepared example text for use in advice.
-
#clean_text ⇒ Object
Clean up the example text, removing unccesseary white lines and triple quote brackets, but keep indention intact.
- #code ⇒ Object
- #code? ⇒ Boolean
-
#data? ⇒ Boolean
Any commentary ending in ‘…` or `:` will mark the following block as a plain text sample and not example code to be evaluated.
- #desc? ⇒ Boolean (also: #description?)
- #flush? ⇒ Boolean
- #head? ⇒ Boolean (also: #header?)
-
#initialize(file) ⇒ Block
constructor
A new instance of Block.
-
#inspect ⇒ Object
TODO: object_hexid.
-
#lineno ⇒ Object
First line of example text.
- #ready!(flush, back_step) ⇒ Object
-
#sample_text ⇒ Object
When the text is sample text and passed to an adivce block, this provides the prepared form of the example text, removing white lines, triple quote brackets and indention.
- #text ⇒ Object
- #to_s ⇒ Object
-
#type ⇒ Object
What type of block is this?.
Constructor Details
Instance Attribute Details
#back_step ⇒ Object (readonly)
previous block
199 200 201 |
# File 'lib/qed/parser.rb', line 199 def back_step @back_step end |
#next_step ⇒ Object
next block
202 203 204 |
# File 'lib/qed/parser.rb', line 202 def next_step @next_step end |
#raw ⇒ Object (readonly)
Block raw code/text.
196 197 198 |
# File 'lib/qed/parser.rb', line 196 def raw @raw end |
Instance Method Details
#arguments ⇒ Object
Returns an Array of prepared example text for use in advice.
250 251 252 253 254 255 256 |
# File 'lib/qed/parser.rb', line 250 def arguments if next_step && next_step.data? [next_step.sample_text] else [] end end |
#clean_text ⇒ Object
Clean up the example text, removing unccesseary white lines and triple quote brackets, but keep indention intact.
295 296 297 298 299 300 301 |
# File 'lib/qed/parser.rb', line 295 def clean_text str = text.chomp.sub(/\A\n/,'') if md = /\A["]{3,}(.*?)["]{3,}\Z/.match(str) str = md[1] end str.rstrip end |
#code ⇒ Object
289 290 291 |
# File 'lib/qed/parser.rb', line 289 def code @code ||= tweak_code end |
#code? ⇒ Boolean
270 |
# File 'lib/qed/parser.rb', line 270 def code? ; @type == :code ; end |
#data? ⇒ Boolean
Any commentary ending in ‘…` or `:` will mark the following block as a plain text sample and not example code to be evaluated.
274 |
# File 'lib/qed/parser.rb', line 274 def data? ; @type == :data ; end |
#desc? ⇒ Boolean Also known as: description?
267 |
# File 'lib/qed/parser.rb', line 267 def desc? ; @type == :desc ; end |
#flush? ⇒ Boolean
244 245 246 |
# File 'lib/qed/parser.rb', line 244 def flush? @flush end |
#head? ⇒ Boolean Also known as: header?
264 |
# File 'lib/qed/parser.rb', line 264 def head? ; @type == :head ; end |
#inspect ⇒ Object
TODO: object_hexid
315 316 317 |
# File 'lib/qed/parser.rb', line 315 def inspect %[#<Block:#{object_id} "#{text[0..25]} ...">] end |
#lineno ⇒ Object
First line of example text.
284 285 286 |
# File 'lib/qed/parser.rb', line 284 def lineno @line ||= @raw.first.first end |
#ready!(flush, back_step) ⇒ Object
216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/qed/parser.rb', line 216 def ready!(flush, back_step) @flush = flush @back_step = back_step @text = raw.map{ |lineno, line| line }.join @type = parse_type @back_step.next_step = self if @back_step self end |
#sample_text ⇒ Object
When the text is sample text and passed to an adivce block, this provides the prepared form of the example text, removing white lines, triple quote brackets and indention.
306 307 308 309 310 311 312 |
# File 'lib/qed/parser.rb', line 306 def sample_text str = text.tabto(0).chomp.sub(/\A\n/,'') if md = /\A["]{3,}(.*?)["]{3,}\Z/.match(str) str = md[1] end str.rstrip end |
#text ⇒ Object
239 240 241 |
# File 'lib/qed/parser.rb', line 239 def text @text end |
#to_s ⇒ Object
229 230 231 232 233 234 235 236 |
# File 'lib/qed/parser.rb', line 229 def to_s case type when :description text else text end end |
#type ⇒ Object
What type of block is this?
259 260 261 |
# File 'lib/qed/parser.rb', line 259 def type @type end |