class Benchin::Wrap::Report::NodePrinter
Human readable {Node} printing.
With TTY colors.
@api private
Constants
- FIELD_SPACE
- PRECISION
- VALUE_SPACE
Public Class Methods
new(node, level: 0)
click to toggle source
@param node [Node] node to print @param level [Integer] defines current level of nesting
# File lib/benchin/wrap/report/node_printer.rb, line 18 def initialize(node, level: 0) @node = node @level = level end
Public Instance Methods
to_s()
click to toggle source
@return [String] rendered report
# File lib/benchin/wrap/report/node_printer.rb, line 24 def to_s [ (@node.is_a?(Node::Virtual) ? virtual_body : body), @node.nested.values.map do |child_node| self.class.new(child_node, level: @level + 1).to_s end ].flatten.join("\n") end
Private Instance Methods
body()
click to toggle source
# File lib/benchin/wrap/report/node_printer.rb, line 45 def body nav = '| ' prefix = nav * @level [ title, nav + calls, nav + time_all, nav + time_self, nav + time_childs ].map { |line| prefix + line }.join("\n") end
calls()
click to toggle source
# File lib/benchin/wrap/report/node_printer.rb, line 62 def calls 'calls:'.ljust(FIELD_SPACE) + Rainbow( @node.calls .to_s .rjust(VALUE_SPACE) ).blue end
time_all()
click to toggle source
# File lib/benchin/wrap/report/node_printer.rb, line 71 def time_all 'time(all):'.ljust(FIELD_SPACE) + Rainbow( @node.total_seconds .truncate(PRECISION) .to_s .rjust(VALUE_SPACE) ).green end
time_childs()
click to toggle source
# File lib/benchin/wrap/report/node_printer.rb, line 91 def time_childs 'time(childs):'.ljust(FIELD_SPACE) + Rainbow( @node.child_seconds .truncate(PRECISION) .to_s .rjust(VALUE_SPACE) ).green end
time_self()
click to toggle source
# File lib/benchin/wrap/report/node_printer.rb, line 81 def time_self 'time(self):'.ljust(FIELD_SPACE) + Rainbow( @node.self_seconds .truncate(PRECISION) .to_s .rjust(VALUE_SPACE) ).green.bright end
title()
click to toggle source
# File lib/benchin/wrap/report/node_printer.rb, line 58 def title "#{Rainbow(@node.name).bright} ->" end
virtual_body()
click to toggle source
# File lib/benchin/wrap/report/node_printer.rb, line 35 def virtual_body nav = '| ' prefix = nav * @level [ title, nav + time_all ].map { |line| prefix + line }.join("\n") end