Class: AsteriskManager::Call

Inherits:
Object
  • Object
show all
Defined in:
lib/asterisk-manager/call.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arguments = {}) ⇒ Call

Returns a new instance of Call.



7
8
9
10
11
# File 'lib/asterisk-manager/call.rb', line 7

def initialize(arguments = {})
  self.channel_1  = arguments[:channel_1]
  self.channel_2  = arguments[:channel_2]
  self.created_at = Time.now
end

Instance Attribute Details

#channel_1Object

Returns the value of attribute channel_1.



3
4
5
# File 'lib/asterisk-manager/call.rb', line 3

def channel_1
  @channel_1
end

#channel_2Object

Returns the value of attribute channel_2.



3
4
5
# File 'lib/asterisk-manager/call.rb', line 3

def channel_2
  @channel_2
end

#created_atObject

Returns the value of attribute created_at.



3
4
5
# File 'lib/asterisk-manager/call.rb', line 3

def created_at
  @created_at
end

Class Method Details

.callsObject



25
26
27
# File 'lib/asterisk-manager/call.rb', line 25

def self.calls
  @calls ||= {}
end

.for_channel_1_and_channel_2(channel_1, channel_2) ⇒ Object



29
30
31
# File 'lib/asterisk-manager/call.rb', line 29

def self.for_channel_1_and_channel_2(channel_1, channel_2)
  calls[ [ channel_1, channel_2 ] ] ||= new(channel_1: channel_1, channel_2: channel_2)
end

Instance Method Details

#durationObject



17
18
19
20
21
22
23
# File 'lib/asterisk-manager/call.rb', line 17

def duration
  x = seconds.round
  hours   = x / 3600
  minutes = (x - hours * 3600) / 60
  seconds = (x - hours * 3600 - minutes * 60)
  "#{hours}:#{'%02d' % minutes}:#{'%02d' % seconds}"
end

#secondsObject



13
14
15
# File 'lib/asterisk-manager/call.rb', line 13

def seconds
  Time.now - created_at
end