Class: Probatio::Node
- Inherits:
-
Object
- Object
- Probatio::Node
- Defined in:
- lib/probatio.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #array_name ⇒ Object
- #depth ⇒ Object
- #filename ⇒ Object
- #full_name ⇒ Object
- #groups ⇒ Object
- #head(opts = {}) ⇒ Object
-
#initialize(parent, path, name, opts, block) ⇒ Node
constructor
A new instance of Node.
- #last_line ⇒ Object
- #line ⇒ Object
- #location ⇒ Object
- #map ⇒ Object
- #name ⇒ Object
- #path_and_line ⇒ Object
- #pending? ⇒ Boolean
- #root ⇒ Object
- #skip?(run_opts) ⇒ Boolean
- #test? ⇒ Boolean
- #to_s(opts = {}) ⇒ Object
- #trail(opts = {}) ⇒ Object
- #type ⇒ Object
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
#block ⇒ Object (readonly)
Returns the value of attribute block.
272 273 274 |
# File 'lib/probatio.rb', line 272 def block @block end |
#children ⇒ Object (readonly)
Returns the value of attribute children.
272 273 274 |
# File 'lib/probatio.rb', line 272 def children @children end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
272 273 274 |
# File 'lib/probatio.rb', line 272 def opts @opts end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
272 273 274 |
# File 'lib/probatio.rb', line 272 def parent @parent end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
272 273 274 |
# File 'lib/probatio.rb', line 272 def path @path end |
Instance Method Details
#array_name ⇒ Object
298 |
# File 'lib/probatio.rb', line 298 def array_name; parent ? parent.array_name + [ name ] : [ name ]; end |
#depth ⇒ Object
295 |
# File 'lib/probatio.rb', line 295 def depth; parent ? parent.depth + 1 : 0; end |
#filename ⇒ Object
290 |
# File 'lib/probatio.rb', line 290 def filename; @filename ||= File.basename(@path); end |
#full_name ⇒ Object
299 |
# File 'lib/probatio.rb', line 299 def full_name; array_name.join(' '); end |
#groups ⇒ Object
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_line ⇒ Object
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 |
#line ⇒ Object
303 304 305 306 |
# File 'lib/probatio.rb', line 303 def line (@block.respond_to?(:source_location) ? @block.source_location : [])[1] end |
#location ⇒ Object
321 322 323 324 |
# File 'lib/probatio.rb', line 321 def location "#{@path}:#{line}" end |
#map ⇒ Object
275 |
# File 'lib/probatio.rb', line 275 def map; @parent ? @parent.map : (@map ||= {}); end |
#name ⇒ Object
297 |
# File 'lib/probatio.rb', line 297 def name; @name || type; end |
#path_and_line ⇒ Object
316 317 318 319 |
# File 'lib/probatio.rb', line 316 def path_and_line [ @path, line ] end |
#pending? ⇒ Boolean
301 |
# File 'lib/probatio.rb', line 301 def pending?; @opts[:pending]; end |
#skip?(run_opts) ⇒ Boolean
359 |
# File 'lib/probatio.rb', line 359 def skip?(run_opts); false; end |
#test? ⇒ 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 |
#type ⇒ Object
292 |
# File 'lib/probatio.rb', line 292 def type; self.class.name.split('::').last.downcase; end |