Class: Probatio::Node

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

Direct Known Subclasses

Leaf, Section

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, path, name, opts, block) ⇒ Node

Returns a new instance of Node.



277
278
279
280
281
282
283
284
285
286
287
288
# File 'lib/probatio.rb', line 277

def initialize(parent, path, name, opts, block)

  @parent = parent
  @path = path
  @name = name
  @opts = opts
  @block = block

  @children = []

  map_self
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



272
273
274
# File 'lib/probatio.rb', line 272

def block
  @block
end

#childrenObject (readonly)

Returns the value of attribute children.



272
273
274
# File 'lib/probatio.rb', line 272

def children
  @children
end

#optsObject (readonly)

Returns the value of attribute opts.



272
273
274
# File 'lib/probatio.rb', line 272

def opts
  @opts
end

#parentObject (readonly)

Returns the value of attribute parent.



272
273
274
# File 'lib/probatio.rb', line 272

def parent
  @parent
end

#pathObject (readonly)

Returns the value of attribute path.



272
273
274
# File 'lib/probatio.rb', line 272

def path
  @path
end

Instance Method Details

#array_nameObject



298
# File 'lib/probatio.rb', line 298

def array_name; parent ? parent.array_name + [ name ] : [ name ]; end

#depthObject



295
# File 'lib/probatio.rb', line 295

def depth; parent ? parent.depth + 1 : 0; end

#filenameObject



290
# File 'lib/probatio.rb', line 290

def filename; @filename ||= File.basename(@path); end

#full_nameObject



299
# File 'lib/probatio.rb', line 299

def full_name; array_name.join(' '); end

#groupsObject



361
362
363
364
# File 'lib/probatio.rb', line 361

def groups

  @children.select { |c| c.is_a?(Probatio::Group) }
end

#head(opts = {}) ⇒ Object



346
# File 'lib/probatio.rb', line 346

def head(opts={}); to_s(opts.merge(head: true)).strip; end

#last_lineObject



308
309
310
311
312
313
314
# File 'lib/probatio.rb', line 308

def last_line

  lln = map[path].find { |l0, l1, n| n == self }

  l = lln && lln[1]
  l && l > 0 ? l : 9_999_999
end

#lineObject



303
304
305
306
# File 'lib/probatio.rb', line 303

def line

  (@block.respond_to?(:source_location) ? @block.source_location : [])[1]
end

#locationObject



321
322
323
324
# File 'lib/probatio.rb', line 321

def location

  "#{@path}:#{line}"
end

#mapObject



275
# File 'lib/probatio.rb', line 275

def map; @parent ? @parent.map : (@map ||= {}); end

#nameObject



297
# File 'lib/probatio.rb', line 297

def name; @name || type; end

#path_and_lineObject



316
317
318
319
# File 'lib/probatio.rb', line 316

def path_and_line

  [ @path, line ]
end

#pending?Boolean

Returns:

  • (Boolean)


301
# File 'lib/probatio.rb', line 301

def pending?; @opts[:pending]; end

#rootObject



274
# File 'lib/probatio.rb', line 274

def root; @parent ? @parent.root : self; end

#skip?(run_opts) ⇒ Boolean

Returns:

  • (Boolean)


359
# File 'lib/probatio.rb', line 359

def skip?(run_opts); false; end

#test?Boolean

Returns:

  • (Boolean)


293
# File 'lib/probatio.rb', line 293

def test?; type == 'test'; end

#to_s(opts = {}) ⇒ Object



326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
# File 'lib/probatio.rb', line 326

def to_s(opts={})

  col = Probatio.c
  out = opts[:out] || StringIO.new
  opts1 = opts.merge(out: out)

  pali = location; pali = pali.chop if pali.end_with?(':')

  out << '  ' * depth
  out << col.yellow(type)
  out << (@name ? ' ' + @name.inspect : '')
  out << (@opts.any? ? ' ' + @opts.inspect : '')
  out << ' ' << col.dark_grey(pali)
  out << "\n"

  @children.each { |c| c.to_s(opts1) } unless opts[:head]

  opts[:out] ? nil : out.string.strip
end

#trail(opts = {}) ⇒ Object



348
349
350
351
352
353
354
355
356
357
# File 'lib/probatio.rb', line 348

def trail(opts={})

  out = opts[:out] || StringIO.new
  opts1 = opts.merge(out: out, head: true)

  parent.trail(opts1) if parent
  to_s(opts1)

  opts[:out] ? nil : out.string.strip
end

#typeObject



292
# File 'lib/probatio.rb', line 292

def type; self.class.name.split('::').last.downcase; end