Class: Fiveruns::Tuneup::RootStep
- Inherits:
-
Object
- Object
- Fiveruns::Tuneup::RootStep
- Includes:
- Templating
- Defined in:
- lib/fiveruns/tuneup/step.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#bar ⇒ Object
readonly
Returns the value of attribute bar.
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#time ⇒ Object
Returns the value of attribute time.
Instance Method Summary collapse
- #add_child(child) ⇒ Object
- #disparity ⇒ Object
- #format_time(time) ⇒ Object
-
#initialize(time = nil) ⇒ RootStep
constructor
A new instance of RootStep.
- #layer_portions ⇒ Object
- #proportion ⇒ Object
- #record ⇒ Object
- #root ⇒ Object
- #template ⇒ Object
- #to_html_with_children ⇒ Object
- #to_json ⇒ Object
Methods included from Templating
Constructor Details
Instance Attribute Details
#bar ⇒ Object (readonly)
Returns the value of attribute bar.
23 24 25 |
# File 'lib/fiveruns/tuneup/step.rb', line 23 def @bar end |
#children ⇒ Object (readonly)
Returns the value of attribute children.
23 24 25 |
# File 'lib/fiveruns/tuneup/step.rb', line 23 def children @children end |
#parent ⇒ Object
Returns the value of attribute parent.
24 25 26 |
# File 'lib/fiveruns/tuneup/step.rb', line 24 def parent @parent end |
#time ⇒ Object
Returns the value of attribute time.
24 25 26 |
# File 'lib/fiveruns/tuneup/step.rb', line 24 def time @time end |
Instance Method Details
#add_child(child) ⇒ Object
50 51 52 53 |
# File 'lib/fiveruns/tuneup/step.rb', line 50 def add_child(child) child.parent = self children << child end |
#disparity ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/fiveruns/tuneup/step.rb', line 41 def disparity result = time - children.inject(0) { |sum, child| sum + child.time } if result < 0 #TODO resolve instances where sum of child times exceed parent time #raise CalculationError, "Child steps exceed parent step size" result = 0 end result end |
#format_time(time) ⇒ Object
54 55 56 |
# File 'lib/fiveruns/tuneup/step.rb', line 54 def format_time(time) '%.2fms' % (time * 1000) end |
#layer_portions ⇒ Object
57 58 59 |
# File 'lib/fiveruns/tuneup/step.rb', line 57 def layer_portions children.first.layer_portions end |
#proportion ⇒ Object
64 65 66 |
# File 'lib/fiveruns/tuneup/step.rb', line 64 def proportion time / root.time end |
#record ⇒ Object
35 36 37 38 39 40 |
# File 'lib/fiveruns/tuneup/step.rb', line 35 def record start = Time.now result = Step.inside(self) { yield } @time = Time.now - start result end |
#root ⇒ Object
31 32 33 |
# File 'lib/fiveruns/tuneup/step.rb', line 31 def root parent ? parent.root : self end |
#template ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'lib/fiveruns/tuneup/step.rb', line 72 def template %( <div id="tuneup-summary"> <%= bar.to_html %> <%= (time * 1000).to_i %> ms </div> ) end |
#to_html_with_children ⇒ Object
68 69 70 |
# File 'lib/fiveruns/tuneup/step.rb', line 68 def to_html_with_children to_html << children.map { |c| c.to_html }.join end |
#to_json ⇒ Object
60 61 62 |
# File 'lib/fiveruns/tuneup/step.rb', line 60 def to_json {:children => children, :time => time}.to_json end |