Class: Gestalt::Call
- Inherits:
-
Object
- Object
- Gestalt::Call
- Defined in:
- lib/gestalt/call.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#binding ⇒ Object
Returns the value of attribute binding.
-
#children ⇒ Object
Returns the value of attribute children.
-
#durations ⇒ Object
Returns the value of attribute durations.
-
#finished_at ⇒ Object
Returns the value of attribute finished_at.
-
#location ⇒ Object
Returns the value of attribute location.
-
#started_at ⇒ Object
Returns the value of attribute started_at.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #display(total, formatador = Formatador.new) ⇒ Object
- #duration ⇒ Object
- #finish ⇒ Object
-
#initialize(attributes = {}) ⇒ Call
constructor
A new instance of Call.
Constructor Details
#initialize(attributes = {}) ⇒ Call
Returns a new instance of Call.
8 9 10 11 12 13 14 15 |
# File 'lib/gestalt/call.rb', line 8 def initialize(attributes = {}) @started_at = Time.now.to_f for key, value in attributes send("#{key}=", value) end @children ||= [] @durations ||= [] end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
6 7 8 |
# File 'lib/gestalt/call.rb', line 6 def action @action end |
#binding ⇒ Object
Returns the value of attribute binding.
6 7 8 |
# File 'lib/gestalt/call.rb', line 6 def binding @binding end |
#children ⇒ Object
Returns the value of attribute children.
5 6 7 |
# File 'lib/gestalt/call.rb', line 5 def children @children end |
#durations ⇒ Object
Returns the value of attribute durations.
5 6 7 |
# File 'lib/gestalt/call.rb', line 5 def durations @durations end |
#finished_at ⇒ Object
Returns the value of attribute finished_at.
6 7 8 |
# File 'lib/gestalt/call.rb', line 6 def finished_at @finished_at end |
#location ⇒ Object
Returns the value of attribute location.
6 7 8 |
# File 'lib/gestalt/call.rb', line 6 def location @location end |
#started_at ⇒ Object
Returns the value of attribute started_at.
6 7 8 |
# File 'lib/gestalt/call.rb', line 6 def started_at @started_at end |
Instance Method Details
#==(other) ⇒ Object
17 18 19 |
# File 'lib/gestalt/call.rb', line 17 def ==(other) action == other.action && location == other.location && children == other.children end |
#display(total, formatador = Formatador.new) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/gestalt/call.rb', line 21 def display(total, formatador = Formatador.new) data = [] data << format("[bold]%.1f%%[/]", (duration / total) * 100.0) if durations.length > 1 data << "[light_black]#{durations.length}x[/]" end data << "[bold]#{action}[/]" data << "[light_black]#{location}[/]" condensed = [] total = 0.0 for call in children if condensed.last && condensed.last == call condensed.last.durations.concat(call.durations) else condensed << call end total += call.duration end formatador.display_line(data.join(' ')) formatador.indent do for child in condensed child.display(total, formatador) end end end |
#duration ⇒ Object
47 48 49 |
# File 'lib/gestalt/call.rb', line 47 def duration durations.inject(0.0) {|memo, duration| duration + memo} end |
#finish ⇒ Object
58 59 60 61 62 63 |
# File 'lib/gestalt/call.rb', line 58 def finish @finished_at ||= Time.now.to_f for child in children child.finish end end |