Sha256: e6aa1f76eeb88e6d82661563e1218561f261de4e43994de7c08683271875148d

Contents?: true

Size: 672 Bytes

Versions: 7

Compression:

Stored size: 672 Bytes

Contents

module Hallmonitor
  class TimedEvent < Event
    attr_accessor :start, :stop

    def initialize(name, duration=nil)
      super(name)
      @duration = duration
    end

    # Duration, should be set in ms, will take precedence over
    # calculating via start and stop times
    attr_writer :duration

    # Reports duration of this timed event in ms
    def duration
      if @duration
        @duration
      elsif @start && @stop
        (@stop - @start) * 1000
      end
    end

    def to_json(*a)
      {
        name: @name,
        time: @time,
        start: @start,
        stop:  @stop,
        duration: self.duration
      }.to_json(*a)
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
hallmonitor-0.4.0 lib/hallmonitor/timed_event.rb
hallmonitor-0.3.0 lib/hallmonitor/timed_event.rb
hallmonitor-0.2.0 lib/hallmonitor/timed_event.rb
hallmonitor-0.1.1 lib/hallmonitor/timed_event.rb
hallmonitor-0.1.0 lib/hallmonitor/timed_event.rb
hallmonitor-0.0.2 lib/hallmonitor/timed_event.rb
hallmonitor-0.0.1 lib/hallmonitor/timed_event.rb