Class: Hallmonitor::TimedEvent

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

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

Returns a new instance of TimedEvent.



5
6
7
8
# File 'lib/hallmonitor/timed_event.rb', line 5

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

Instance Attribute Details

#durationObject

Reports duration of this timed event in ms



15
16
17
18
19
20
21
# File 'lib/hallmonitor/timed_event.rb', line 15

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

#startObject

Returns the value of attribute start.



3
4
5
# File 'lib/hallmonitor/timed_event.rb', line 3

def start
  @start
end

#stopObject

Returns the value of attribute stop.



3
4
5
# File 'lib/hallmonitor/timed_event.rb', line 3

def stop
  @stop
end

Instance Method Details

#to_json(*a) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/hallmonitor/timed_event.rb', line 23

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