Sha256: 487ffe08671765b1f8752aa3a565a782fac45315d36b83e67009f32d1a210b8c

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

module Blather
class Stanza

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

    register :message

    def self.new(to = nil, type = nil, body = nil)
      elem = super()
      elem.to = to
      elem.type = type
      elem.body = body
      elem
    end

    ##
    # 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

    def body=(body)
      remove_child :body
      self << XMPPNode.new('body', body) if body
    end

    def body
      content_from :body
    end

    def subject=(subject)
      remove_child :subject
      self << XMPPNode.new('subject', subject) if subject
    end

    def subject
      content_from :subject
    end

    def thread=(thread)
      remove_child :thread
      self << XMPPNode.new('body', body) if body
    end

    def thread
      content_from :thread
    end
  end

end #Stanza
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
blather-0.1 lib/blather/core/stanza/message.rb