Class: Blather::Stanza::PubSubItem
- Inherits:
-
XMPPNode
- Object
- Nokogiri::XML::Node
- XMPPNode
- 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, #content_from, import, #inherit, #inherit_attrs, #inspect, #namespace=, #namespace_href, #nokogiri_namespace=, #read_attr, #read_content, register, #remove_child, #remove_children, #set_content_for, #to_stanza, #write_attr
Methods inherited from Nokogiri::XML::Node
#[]=, #attr_set, #find_first, #nokogiri_xpath, #xpath
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
98 99 100 |
# File 'lib/blather/stanza/pubsub.rb', line 98 def payload children.empty? ? nil : children.to_s end |
#payload=(payload) ⇒ Object
Set the item’s payload
105 106 107 108 109 110 111 112 113 |
# File 'lib/blather/stanza/pubsub.rb', line 105 def payload=(payload) children.map &:remove return unless payload if payload.is_a?(String) self.content = payload else self << payload end end |