Sha256: c727dc78f1539c295a10ea9939b0862cf55d4f78666f130d5d6b725f090d5572

Contents?: true

Size: 1.02 KB

Versions: 2

Compression:

Stored size: 1.02 KB

Contents

module Blather
class Stanza

  ##
  # Base Message stanza
  class Message < Stanza
    VALID_TYPES = [:chat, :error, :groupchat, :headline, :normal]

    register :message

    def self.import(node)
      klass = nil
      node.children.each { |e| break if klass = class_from_registration(e.element_name, (e.namespace.href if e.namespace)) }

      if klass && klass != self
        klass.import(node)
      else
        new(node[:type]).inherit(node)
      end
    end

    def self.new(to = nil, body = nil, type = :chat)
      node = super(:message)
      node.to = to
      node.type = type
      node.body = body
      node
    end

    attribute_helpers_for :type, VALID_TYPES

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

    content_attr_accessor :body
    content_attr_accessor :subject
    content_attr_accessor :thread
  end

end #Stanza
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
sprsquish-blather-0.4.1 lib/blather/stanza/message.rb
blather-0.4.1 lib/blather/stanza/message.rb