Class: Insight::TemplatesPanel::Rendering

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, timing = nil) ⇒ Rendering

Returns a new instance of Rendering.



10
11
12
13
14
# File 'lib/insight/panels/templates_panel/rendering.rb', line 10

def initialize(name, timing = nil)
  @name = name
  @timing = timing
  @children = []
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



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

def children
  @children
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/insight/panels/templates_panel/rendering.rb', line 5

def name
  @name
end

#parentObject

Returns the value of attribute parent.



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

def parent
  @parent
end

#timingObject

Returns the value of attribute timing.



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

def timing
  @timing
end

Instance Method Details

#add(rendering) ⇒ Object



25
26
27
28
# File 'lib/insight/panels/templates_panel/rendering.rb', line 25

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

#child_durationObject



46
47
48
# File 'lib/insight/panels/templates_panel/rendering.rb', line 46

def child_duration
  children.inject(0.0) { |memo, c| memo + c.duration }
end

#children_htmlObject



67
68
69
70
71
72
73
# File 'lib/insight/panels/templates_panel/rendering.rb', line 67

def children_html
  return "" unless children.any?

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

#delete(rendering) ⇒ Object



30
31
32
# File 'lib/insight/panels/templates_panel/rendering.rb', line 30

def delete(rendering)
  @children.delete(rendering)
end

#durationObject



34
35
36
37
38
39
40
# File 'lib/insight/panels/templates_panel/rendering.rb', line 34

def duration
  if @timing
    @timing.duration
  else
    child_duration
  end
end

#duration_summaryObject



50
51
52
53
54
55
56
# File 'lib/insight/panels/templates_panel/rendering.rb', line 50

def duration_summary
  if children.any?
    "%.2fms, %.2f exclusive" % [duration, exclusive_duration]
  else
    "%.2fms" % (duration)
  end
end

#end_timeObject



21
22
23
# File 'lib/insight/panels/templates_panel/rendering.rb', line 21

def end_time
  @timing.end
end

#exclusive_durationObject



42
43
44
# File 'lib/insight/panels/templates_panel/rendering.rb', line 42

def exclusive_duration
  duration - child_duration
end

#htmlObject



57
58
59
60
61
62
63
64
65
# File 'lib/insight/panels/templates_panel/rendering.rb', line 57

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

  #{children_html}
      </li>
  HTML
end

#joined_children_htmlObject



75
76
77
# File 'lib/insight/panels/templates_panel/rendering.rb', line 75

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

#start_timeObject Also known as: time



16
17
18
# File 'lib/insight/panels/templates_panel/rendering.rb', line 16

def start_time
  @timing.start
end