Sha256: 0dc72c414e4a42b16479439a60f914b682fe35638f8cf7f0819f8dd19575ae67

Contents?: true

Size: 1.52 KB

Versions: 6

Compression:

Stored size: 1.52 KB

Contents

class Gestalt

  class Call

    attr_accessor :children, :durations
    attr_accessor :action, :finished_at, :location, :started_at

    def initialize(attributes = {})
      @started_at = Time.now.to_f
      for key, value in attributes
        send("#{key}=", value)
      end
      @children ||= []
      @durations ||= []
    end

    def ==(other)
      action == other.action && location == other.location && children == other.children
    end

    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

    def duration
      durations.inject(0.0) {|memo, duration| duration + memo}
    end

    def durations
      if @durations.empty?
        @durations << finished_at - started_at
      end
      @durations
    end

    def finish
      @finished_at ||= Time.now.to_f
      for child in children
        child.finish
      end
    end

  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
gestalt-0.0.7 lib/gestalt/call.rb
gestalt-0.0.6 lib/gestalt/call.rb
gestalt-0.0.5 lib/gestalt/call.rb
gestalt-0.0.4 lib/gestalt/call.rb
gestalt-0.0.3 lib/gestalt/call.rb
gestalt-0.0.2 lib/gestalt/call.rb