class Blather::Stanza::PubSub::Affiliations

# PubSub Affiliations Stanza

[XEP-0060 Section 8.9 - Manage Affiliations](xmpp.org/extensions/xep-0060.html#owner-affiliations)

@handler :pubsub_affiliations

Public Class Methods

new(type = nil, host = nil) click to toggle source

Overrides the parent to ensure an affiliation node is created @private

Calls superclass method Blather::Stanza::PubSub::new
# File lib/blather/stanza/pubsub/affiliations.rb, line 18
def self.new(type = nil, host = nil)
  new_node = super
  new_node.affiliations
  new_node
end

Public Instance Methods

affiliations() click to toggle source

Get or create the affiliations node

@return [Blather::XMPPNode]

# File lib/blather/stanza/pubsub/affiliations.rb, line 34
def affiliations
  aff = pubsub.find_first('ns:affiliations', :ns => self.class.registered_ns)
  unless aff
    self.pubsub << (aff = XMPPNode.new('affiliations', self.document))
  end
  aff
end
each(&block) click to toggle source

Convenience method for iterating over the list

@see list for the format of the yielded input

# File lib/blather/stanza/pubsub/affiliations.rb, line 45
def each(&block)
  list.each &block
end
inherit(node) click to toggle source

Kill the affiliations node before running inherit @private

Calls superclass method Blather::Stanza::PubSub#inherit
# File lib/blather/stanza/pubsub/affiliations.rb, line 26
def inherit(node)
  affiliations.remove
  super
end
list() click to toggle source

Get the hash of affilations as affiliation-type => [nodes]

@example

{ :owner => ['node1', 'node2'],
  :publisher => ['node3'],
  :outcast => ['node4'],
  :member => ['node5'],
  :none => ['node6'] }

@return [Hash<String => Array<String>>]

# File lib/blather/stanza/pubsub/affiliations.rb, line 67
def list
  items = affiliations.find('//ns:affiliation', :ns => self.class.registered_ns)
  items.inject({}) do |hash, item|
    hash[item[:affiliation].to_sym] ||= []
    hash[item[:affiliation].to_sym] << item[:node]
    hash
  end
end
size() click to toggle source

Get the number of affiliations

@return [Fixnum]

# File lib/blather/stanza/pubsub/affiliations.rb, line 52
def size
  list.size
end