Class: Blather::Stanza::PubSubItem
- 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
Class Method Summary collapse
-
.new(id = nil, payload = nil, document = nil) ⇒ Object
Create a new PubSubItem.
Instance Method Summary collapse
-
#id ⇒ String?
Get the item’s ID.
-
#id=(id) ⇒ Object
Set the item’s ID.
-
#payload ⇒ String?
Get the item’s payload.
-
#payload=(payload) ⇒ Object
Set the item’s payload.
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.
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
#id ⇒ String?
Get the item’s ID
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
91 92 93 |
# File 'lib/blather/stanza/pubsub.rb', line 91 def id=(id) write_attr :id, id end |
#payload ⇒ String?
Get the item’s payload
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
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 |