Class: RubyAMI::Event

Inherits:
Response show all
Defined in:
lib/ruby_ami/event.rb

Instance Attribute Summary collapse

Attributes inherited from Response

#events, #text_body

Instance Method Summary collapse

Methods inherited from Response

#[], #[]=, #action_id, #eql?, from_immediate_response, #has_text_body?, #headers, #inspect

Constructor Details

#initialize(name, headers = {}) ⇒ Event

Returns a new instance of Event



10
11
12
13
14
# File 'lib/ruby_ami/event.rb', line 10

def initialize(name, headers = {})
  @receipt_time = DateTime.now
  super headers
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name



8
9
10
# File 'lib/ruby_ami/event.rb', line 8

def name
  @name
end

#receipt_timeObject (readonly)

Returns the value of attribute receipt_time



8
9
10
# File 'lib/ruby_ami/event.rb', line 8

def receipt_time
  @receipt_time
end

Instance Method Details

#best_timeDateTime

Returns the best known timestamp for the event. Either its timestamp if specified, or its receipt time if not.

Returns:

  • (DateTime)

    the best known timestamp for the event. Either its timestamp if specified, or its receipt time if not.



23
24
25
# File 'lib/ruby_ami/event.rb', line 23

def best_time
  timestamp || receipt_time
end

#inspect_attributesObject



27
28
29
# File 'lib/ruby_ami/event.rb', line 27

def inspect_attributes
  [:name] + super
end

#timestampDateTime?

Returns the timestamp of the event, or nil if none is available

Returns:

  • (DateTime, nil)

    the timestamp of the event, or nil if none is available



17
18
19
20
# File 'lib/ruby_ami/event.rb', line 17

def timestamp
  return unless headers['Timestamp']
  DateTime.strptime headers['Timestamp'], '%s'
end