Class: Hallmonitor::TimedEvent

Inherits:
Event
  • Object
show all
Defined in:
lib/hallmonitor/timed_event.rb

Overview

An event that represents a span of time

Instance Attribute Summary collapse

Attributes inherited from Event

#count, #name, #time

Instance Method Summary collapse

Methods included from Monitored

#emit, included, #watch

Constructor Details

#initialize(name, duration = nil) ⇒ TimedEvent

Parameters:

  • name (String)

    name of this event

  • duration (Number) (defaults to: nil)

    the timespan of this event



14
15
16
17
# File 'lib/hallmonitor/timed_event.rb', line 14

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

Instance Attribute Details

#durationNumber

Reports duration of this timed event in ms

Returns:

  • (Number)

    duration, in ms if calculated based on #start and #stop



28
29
30
31
32
33
34
# File 'lib/hallmonitor/timed_event.rb', line 28

def duration
  if @duration
    @duration
  elsif @start && @stop
    (@stop - @start) * 1000
  end
end

#startDateTime

Returns the start time of this timed event.

Returns:

  • (DateTime)

    the start time of this timed event



9
10
11
# File 'lib/hallmonitor/timed_event.rb', line 9

def start
  @start
end

#stopDateTime

Returns the stop time of this timed event.

Returns:

  • (DateTime)

    the stop time of this timed event



9
# File 'lib/hallmonitor/timed_event.rb', line 9

attr_accessor :start, :stop

Instance Method Details

#to_json(*a) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/hallmonitor/timed_event.rb', line 36

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