Sha256: aac1515af4370c2eabd75c7c22fddb4475d2e68688f065c82a91d227e9fa12a5

Contents?: true

Size: 1.15 KB

Versions: 14

Compression:

Stored size: 1.15 KB

Contents

module Blather
class Stanza

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

    register :message

    def initialize(to = nil, body = nil, type = :chat)
      super()
      self.to = to
      self.type = type
      self.body = body
    end

    VALID_TYPES.each do |valid_type|
      define_method("#{valid_type}?") { self.type == valid_type }
    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('thread', thread) if thread
    end

    def thread
      content_from :thread
    end
  end

end #Stanza
end

Version data entries

14 entries across 14 versions & 2 rubygems

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