Class: Parlour::Debugging::Tree
- Inherits:
 - 
      Object
      
        
- Object
 - Parlour::Debugging::Tree
 
 
- Extended by:
 - T::Sig
 
- Defined in:
 - lib/parlour/debugging.rb
 
Overview
A module for generating a globally-consistent, nicely-formatted tree of output using Unicode block characters.
Constant Summary collapse
- INDENT_SPACES =
          
The number of spaces to indent each layer of the tree by. Should be at least 1.
 2
Instance Attribute Summary collapse
- 
  
    
      #colour  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute colour.
 
Instance Method Summary collapse
- #begin(message) ⇒ Object
 - #end(message) ⇒ Object
 - #here(message) ⇒ Object
 - 
  
    
      #indent!(offset)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Modifies the current indent level by the given offset.
 - 
  
    
      #initialize(colour: false)  ⇒ Tree 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of Tree.
 - 
  
    
      #line_prefix  ⇒ String 
    
    
  
  
  
  
  
  
  
  
  
    
The prefix which should be printed before anything else on this line of the tree, based on the current indent level.
 - 
  
    
      #text_prefix  ⇒ String 
    
    
  
  
  
  
  
  
  
  
  
    
The horizontal lines which should be printed between the beginning of the current element and its text, based on the specified number of spaces to use for indents.
 
Constructor Details
#initialize(colour: false) ⇒ Tree
Returns a new instance of Tree.
      78 79 80 81  | 
    
      # File 'lib/parlour/debugging.rb', line 78 def initialize(colour: false) @colour = colour @indent_level = 0 end  | 
  
Instance Attribute Details
#colour ⇒ Object (readonly)
Returns the value of attribute colour.
      75 76 77  | 
    
      # File 'lib/parlour/debugging.rb', line 75 def colour @colour end  | 
  
Instance Method Details
#begin(message) ⇒ Object
      88 89 90 91 92 93  | 
    
      # File 'lib/parlour/debugging.rb', line 88 def begin() result = line_prefix + '├' + text_prefix + (colour ? Rainbow().green.bright.bold : ) indent!(1) result end  | 
  
#end(message) ⇒ Object
      108 109 110 111 112  | 
    
      # File 'lib/parlour/debugging.rb', line 108 def end() result = line_prefix + '└' + text_prefix + indent!(-1) result end  | 
  
#here(message) ⇒ Object
      99 100 101  | 
    
      # File 'lib/parlour/debugging.rb', line 99 def here() line_prefix + '├' + text_prefix + end  | 
  
#indent!(offset) ⇒ Object
Modifies the current indent level by the given offset.
      130 131 132  | 
    
      # File 'lib/parlour/debugging.rb', line 130 def indent!(offset) @indent_level = [0, @indent_level + offset].max end  | 
  
#line_prefix ⇒ String
The prefix which should be printed before anything else on this line of the tree, based on the current indent level.
      117 118 119  | 
    
      # File 'lib/parlour/debugging.rb', line 117 def line_prefix @indent_level.times.map { '│' + ' ' * INDENT_SPACES }.join end  | 
  
#text_prefix ⇒ String
The horizontal lines which should be printed between the beginning of the current element and its text, based on the specified number of spaces to use for indents.
      125 126 127  | 
    
      # File 'lib/parlour/debugging.rb', line 125 def text_prefix '─' * (INDENT_SPACES - 1) + " " end  |