Class: Blather::Stanza::PubSubItem

Inherits:
XMPPNode
  • Object
show all
Defined in:
lib/blather/stanza/pubsub.rb

Overview

# PubSubItem Fragment

This fragment is found in many places throughout the pubsub spec This is a convenience class to attach methods to the node

Constant Summary

Constants inherited from XMPPNode

XMPPNode::BASE_NAMES

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from XMPPNode

class_from_registration, #decorate, decorator_modules, import, parse, register, #to_stanza

Class Method Details

.new(id = nil, payload = nil, document = nil) ⇒ Object

Create a new PubSubItem

attached to. This should be the document of the parent PubSub node.

Parameters:

  • id (String, nil) (defaults to: nil)

    the id of the stanza

  • payload (#to_s, nil) (defaults to: nil)

    the payload to attach to this item.

  • document (XML::Document, nil) (defaults to: nil)

    the document the node should be



74
75
76
77
78
79
# File 'lib/blather/stanza/pubsub.rb', line 74

def self.new(id = nil, payload = nil, document = nil)
  new_node = super 'item', document
  new_node.id = id
  new_node.payload = payload if payload
  new_node
end

Instance Method Details

#idString?

Get the item’s ID

Returns:

  • (String, nil)


84
85
86
# File 'lib/blather/stanza/pubsub.rb', line 84

def id
  read_attr :id
end

#id=(id) ⇒ Object

Set the item’s ID

Parameters:

  • id (#to_s)

    the new ID



91
92
93
# File 'lib/blather/stanza/pubsub.rb', line 91

def id=(id)
  write_attr :id, id
end

#payloadString?

Get the item’s payload

Returns:

  • (String, nil)


100
101
102
# File 'lib/blather/stanza/pubsub.rb', line 100

def payload
  children.empty? ? nil : children.to_s
end

#payload=(payload) ⇒ Object

Set the item’s payload

Parameters:

  • payload (String, XMPPNode, nil)

    the payload



107
108
109
110
111
112
113
114
115
# File 'lib/blather/stanza/pubsub.rb', line 107

def payload=(payload)
  children.map &:remove
  return unless payload
  if payload.is_a?(String)
    self.content = payload
  else
    self << payload
  end
end