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 80 81 |
# File 'lib/blather/stanza/pubsub.rb', line 74 def self.new(id = nil, payload = nil, document = nil) return id if id.class == self 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
86 87 88 |
# File 'lib/blather/stanza/pubsub.rb', line 86 def id read_attr :id end |
#id=(id) ⇒ Object
Set the item’s ID
93 94 95 |
# File 'lib/blather/stanza/pubsub.rb', line 93 def id=(id) write_attr :id, id end |
#payload ⇒ String?
Get the item’s payload
102 103 104 |
# File 'lib/blather/stanza/pubsub.rb', line 102 def payload children.empty? ? nil : children.to_s end |
#payload=(payload) ⇒ Object
Set the item’s payload
109 110 111 112 113 114 115 116 117 |
# File 'lib/blather/stanza/pubsub.rb', line 109 def payload=(payload) children.map &:remove return unless payload if payload.is_a?(String) self.content = payload else self << payload end end |