Class: Punchblock::Event::Asterisk::AMI::Event

Inherits:
Punchblock::Event show all
Defined in:
lib/punchblock/event/asterisk/ami/event.rb

Defined Under Namespace

Classes: Attribute

Constant Summary

Constants inherited from RayoNode

RayoNode::InvalidNodeError

Instance Attribute Summary

Attributes inherited from RayoNode

#client, #component_id, #connection, #domain, #original_component, #target_call_id, #target_mixer_name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RayoNode

class_from_registration, #eql?, import, #inspect, register, #source

Class Method Details

.new(options = {}) ⇒ Object



12
13
14
15
16
# File 'lib/punchblock/event/asterisk/ami/event.rb', line 12

def self.new(options = {})
  super().tap do |new_node|
    options.each_pair { |k,v| new_node.send :"#{k}=", v }
  end
end

Instance Method Details

#attributesArray[Attribute]

Returns attributes.

Returns:



39
40
41
42
43
# File 'lib/punchblock/event/asterisk/ami/event.rb', line 39

def attributes
  find('//ns:attribute', :ns => self.class.registered_ns).map do |i|
    Attribute.new i
  end
end

#attributes=(attributes) ⇒ Object

Parameters:

  • attributes (Hash, Array)

    A hash of key-value attribute pairs, or an array of Attribute objects



48
49
50
51
52
53
54
55
# File 'lib/punchblock/event/asterisk/ami/event.rb', line 48

def attributes=(attributes)
  find('//ns:attribute', :ns => self.class.registered_ns).each(&:remove)
  if attributes.is_a? Hash
    attributes.each_pair { |k,v| self << Attribute.new(k, v) }
  elsif attributes.is_a? Array
    [attributes].flatten.each { |i| self << Attribute.new(i) }
  end
end

#attributes_hashHash

Returns hash of key-value pairs of attributes.

Returns:

  • (Hash)

    hash of key-value pairs of attributes



29
30
31
32
33
34
# File 'lib/punchblock/event/asterisk/ami/event.rb', line 29

def attributes_hash
  attributes.inject({}) do |hash, attribute|
    hash[attribute.name.downcase.gsub('-', '_').to_sym] = attribute.value
    hash
  end
end

#inspect_attributesObject

:nodoc:



57
58
59
# File 'lib/punchblock/event/asterisk/ami/event.rb', line 57

def inspect_attributes # :nodoc:
  [:name, :attributes_hash] + super
end

#nameObject



18
19
20
# File 'lib/punchblock/event/asterisk/ami/event.rb', line 18

def name
  read_attr :name
end

#name=(other) ⇒ Object



22
23
24
# File 'lib/punchblock/event/asterisk/ami/event.rb', line 22

def name=(other)
  write_attr :name, other
end