Sha256: a6d9f117fae93beb8b2d87f9f2ad74fd3821addf11d685f7d5e41c834e417ddc

Contents?: true

Size: 996 Bytes

Versions: 13

Compression:

Stored size: 996 Bytes

Contents

module Blather
class Stanza

  ##
  # Base Iq stanza
  class Iq < Stanza
    VALID_TYPES = [:get, :set, :result, :error]

    register :iq

    def self.import(node)
      raise(ArgumentError, "Import missmatch #{[node.element_name, self.name].inspect}") if node.element_name != self.name.to_s
      klass = nil
      node.children.each { |e| break if klass = class_from_registration(e.element_name, e.namespace) }
      (klass || self).new(node.attributes[:type]).inherit(node)
    end

    def initialize(type = nil, to = nil, id = nil)
      super :iq
      self.type = type || :get
      self.to = to
      self.id = id if id
    end

    VALID_TYPES.each do |valid_type|
      define_method("#{valid_type}?") { self.type == valid_type }
    end

    ##
    # Ensures type is :get, :set, :result or :error
    def type=(type)
      raise ArgumentError, "Invalid Type (#{type}), use: #{VALID_TYPES*' '}" if type && !VALID_TYPES.include?(type.to_sym)
      super
    end
  end

end #Stanza
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
sprsquish-blather-0.2.3 lib/blather/stanza/iq.rb
sprsquish-blather-0.3.0 lib/blather/stanza/iq.rb
sprsquish-blather-0.3.1 lib/blather/stanza/iq.rb
sprsquish-blather-0.3.2 lib/blather/stanza/iq.rb
sprsquish-blather-0.3.3 lib/blather/stanza/iq.rb
sprsquish-blather-0.3.4 lib/blather/stanza/iq.rb
blather-0.2.2 lib/blather/stanza/iq.rb
blather-0.3.1 lib/blather/stanza/iq.rb
blather-0.2.3 lib/blather/stanza/iq.rb
blather-0.3.0 lib/blather/stanza/iq.rb
blather-0.3.4 lib/blather/stanza/iq.rb
blather-0.3.2 lib/blather/stanza/iq.rb
blather-0.3.3 lib/blather/stanza/iq.rb