Class: Blather::Stanza::PubSubItem

Inherits:
XMPPNode 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, #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.

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:



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

Parameters:

  • payload (String, XMPPNode, nil)

    the 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