Sha256: 1b01a692ef4672c26884122f89bbd40d80f2a26614ef0030de38d327dc549cd7

Contents?: true

Size: 1.79 KB

Versions: 12

Compression:

Stored size: 1.79 KB

Contents

# encoding: utf-8

require 'punchblock/key_value_pair_node'

module Punchblock
  class Event
    module Asterisk
      module AMI
        class Event < Punchblock::Event
          register :event, :ami

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

          def name
            read_attr :name
          end

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

          ##
          # @return [Hash] hash of key-value pairs of attributes
          #
          def attributes_hash
            attributes.inject({}) do |hash, attribute|
              hash[attribute.name.downcase.gsub('-', '_').to_sym] = attribute.value
              hash
            end
          end

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

          ##
          # @param [Hash, Array] attributes A hash of key-value attribute pairs, or an array of Attribute objects
          #
          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

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

          class Attribute < RayoNode
            include KeyValuePairNode
          end
        end
      end
    end
  end # Command
end # Punchblock

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
punchblock-1.9.4 lib/punchblock/event/asterisk/ami/event.rb
punchblock-1.9.3 lib/punchblock/event/asterisk/ami/event.rb
punchblock-1.9.2 lib/punchblock/event/asterisk/ami/event.rb
punchblock-1.9.1 lib/punchblock/event/asterisk/ami/event.rb
punchblock-1.9.0 lib/punchblock/event/asterisk/ami/event.rb
punchblock-1.8.2 lib/punchblock/event/asterisk/ami/event.rb
punchblock-1.8.1 lib/punchblock/event/asterisk/ami/event.rb
punchblock-1.8.0 lib/punchblock/event/asterisk/ami/event.rb
punchblock-1.7.1 lib/punchblock/event/asterisk/ami/event.rb
punchblock-1.7.0 lib/punchblock/event/asterisk/ami/event.rb
punchblock-1.6.1 lib/punchblock/event/asterisk/ami/event.rb
punchblock-1.6.0 lib/punchblock/event/asterisk/ami/event.rb