Class: AsteriskManager::Channel

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arguments = {}) ⇒ Channel

Returns a new instance of Channel.



12
13
14
15
16
17
18
19
20
21
# File 'lib/asterisk-manager/channel.rb', line 12

def initialize(arguments = {})
  self.unique_id        = arguments[:unique_id]
  self.sip_id           = arguments[:sip_id]
  self.state            = arguments[:state]
  self.caller_id_number = arguments[:caller_id_number]
  self.caller_id_name   = arguments[:caller_id_name]
  self.application_name = arguments[:application_name]
  self.application_data = arguments[:application_data]
  self.created_at       = Time.now
end

Instance Attribute Details

#application_dataObject

Returns the value of attribute application_data.



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

def application_data
  @application_data
end

#application_nameObject

Returns the value of attribute application_name.



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

def application_name
  @application_name
end

#caller_id_nameObject

Returns the value of attribute caller_id_name.



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

def caller_id_name
  @caller_id_name
end

#caller_id_numberObject

Returns the value of attribute caller_id_number.



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

def caller_id_number
  @caller_id_number
end

#created_atObject

Returns the value of attribute created_at.



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

def created_at
  @created_at
end

#sip_idObject

Returns the value of attribute sip_id.



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

def sip_id
  @sip_id
end

#stateObject

Returns the value of attribute state.



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

def state
  @state
end

#unique_idObject

Returns the value of attribute unique_id.



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

def unique_id
  @unique_id
end

Class Method Details

.channelsObject



47
48
49
# File 'lib/asterisk-manager/channel.rb', line 47

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

.for_unique_id(unique_id) ⇒ Object



51
52
53
# File 'lib/asterisk-manager/channel.rb', line 51

def self.for_unique_id(unique_id)
  channels[unique_id] ||= new(unique_id: unique_id)
end

Instance Method Details

#<=>(other_channel) ⇒ Object



43
44
45
# File 'lib/asterisk-manager/channel.rb', line 43

def <=>(other_channel)
  unique_id.to_f <=> other_channel.unique_id.to_f
end

#applicationObject



23
24
25
# File 'lib/asterisk-manager/channel.rb', line 23

def application
  "#{application_name}(#{application_data})" if application_name.to_s.size > 0
end

#caller_idObject



27
28
29
# File 'lib/asterisk-manager/channel.rb', line 27

def caller_id
  "#{caller_id_number} #{caller_id_name}".strip
end

#durationObject



35
36
37
38
39
40
41
# File 'lib/asterisk-manager/channel.rb', line 35

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



31
32
33
# File 'lib/asterisk-manager/channel.rb', line 31

def seconds
  Time.now - created_at
end