Class: Punchblock::Component::Asterisk::AMI::Action

Inherits:
ComponentNode show all
Defined in:
lib/punchblock/component/asterisk/ami/action.rb

Defined Under Namespace

Classes: Complete, Param

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 ComponentNode

#add_event, #complete_event, #complete_event=, #initialize, #register_event_handler, #register_internal_handlers, #response=, #stop!, #stop_action, #trigger_event_handler, #write_action

Methods inherited from Punchblock::CommandNode

#initialize, #response, #response=, #write_attr

Methods inherited from RayoNode

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

Constructor Details

This class inherits a constructor from Punchblock::Component::ComponentNode

Class Method Details

.new(options = {}) ⇒ Object



12
13
14
15
16
# File 'lib/punchblock/component/asterisk/ami/action.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

#inspect_attributesObject

:nodoc:



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

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

#nameObject



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

def name
  read_attr :name
end

#name=(other) ⇒ Object



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

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

#paramsArray[Param]

Returns params.

Returns:

  • (Array[Param])

    params



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

def params
  find('//ns:param', :ns => self.class.registered_ns).map do |i|
    Param.new i
  end
end

#params=(params) ⇒ Object

Parameters:

  • params (Hash, Array)

    A hash of key-value param pairs, or an array of Param objects



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

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

#params_hashHash

Returns hash of key-value pairs of params.

Returns:

  • (Hash)

    hash of key-value pairs of params



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

def params_hash
  params.inject({}) do |hash, param|
    hash[param.name.downcase.gsub('-', '_').to_sym] = param.value
    hash
  end
end