Class: Rack::Bug::TemplatesPanel::Rendering

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/bug/panels/templates_panel/rendering.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Rendering

Returns a new instance of Rendering.



13
14
15
16
# File 'lib/rack/bug/panels/templates_panel/rendering.rb', line 13

def initialize(name)
  @name = name
  @children = []
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



10
11
12
# File 'lib/rack/bug/panels/templates_panel/rendering.rb', line 10

def children
  @children
end

#end_timeObject

Returns the value of attribute end_time.



8
9
10
# File 'lib/rack/bug/panels/templates_panel/rendering.rb', line 8

def end_time
  @end_time
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/rack/bug/panels/templates_panel/rendering.rb', line 6

def name
  @name
end

#parentObject

Returns the value of attribute parent.



9
10
11
# File 'lib/rack/bug/panels/templates_panel/rendering.rb', line 9

def parent
  @parent
end

#start_timeObject

Returns the value of attribute start_time.



7
8
9
# File 'lib/rack/bug/panels/templates_panel/rendering.rb', line 7

def start_time
  @start_time
end

Instance Method Details

#add(rendering) ⇒ Object



18
19
20
21
# File 'lib/rack/bug/panels/templates_panel/rendering.rb', line 18

def add(rendering)
  @children << rendering
  rendering.parent = self
end

#child_timeObject



31
32
33
# File 'lib/rack/bug/panels/templates_panel/rendering.rb', line 31

def child_time
  children.inject(0.0) { |memo, c| memo + c.time }
end

#children_htmlObject



52
53
54
55
56
57
58
# File 'lib/rack/bug/panels/templates_panel/rendering.rb', line 52

def children_html
  return "" unless children.any?

  <<-HTML
    <ul>#{joined_children_html}</ul>
  HTML
end

#exclusive_timeObject



27
28
29
# File 'lib/rack/bug/panels/templates_panel/rendering.rb', line 27

def exclusive_time
  time - child_time
end

#htmlObject



42
43
44
45
46
47
48
49
50
# File 'lib/rack/bug/panels/templates_panel/rendering.rb', line 42

def html
  <<-HTML
    <li>
      <p>#{name} (#{time_summary})</p>

      #{children_html}
    </li>
  HTML
end

#joined_children_htmlObject



60
61
62
# File 'lib/rack/bug/panels/templates_panel/rendering.rb', line 60

def joined_children_html
  children.map { |c| c.html }.join
end

#timeObject



23
24
25
# File 'lib/rack/bug/panels/templates_panel/rendering.rb', line 23

def time
  @end_time - @start_time
end

#time_summaryObject



35
36
37
38
39
40
41
# File 'lib/rack/bug/panels/templates_panel/rendering.rb', line 35

def time_summary
  if children.any?
    "%.2fms, %.2f exclusive" % [time * 1_000, exclusive_time * 1_000]
  else
    "%.2fms" % (time * 1_000)
  end
end