Class: Blather::Stanza::PubSub::Affiliations

Inherits:
Blather::Stanza::PubSub show all
Includes:
Enumerable
Defined in:
lib/blather/stanza/pubsub/affiliations.rb

Overview

# PubSub Affiliations Stanza

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

Constant Summary

Constants inherited from Iq

Iq::VALID_TYPES

Constants inherited from XMPPNode

XMPPNode::BASE_NAMES

Instance Attribute Summary

Attributes inherited from Blather::Stanza

#handler_hierarchy

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Blather::Stanza::PubSub

import, #pubsub

Methods inherited from Iq

#error?, #get?, import, #reply!, #result?, #set?, #type=

Methods inherited from Blather::Stanza

#as_error, #error?, #from, #from=, handler_list, #id, #id=, #initialize, next_id, register, #reply, #reply!, #to, #to=, #type, #type=

Methods inherited from XMPPNode

class_from_registration, #decorate, decorator_modules, import, parse, register, #to_stanza

Constructor Details

This class inherits a constructor from Blather::Stanza

Class Method Details

.new(type = nil, host = nil) ⇒ Object

Overrides the parent to ensure an affiliation node is created



18
19
20
21
22
# 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

Instance Method Details

#affiliationsBlather::XMPPNode

Get or create the affiliations node

Returns:



34
35
36
37
38
39
40
# 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) ⇒ Object

Convenience method for iterating over the list



45
46
47
# File 'lib/blather/stanza/pubsub/affiliations.rb', line 45

def each(&block)
  list.each &block
end

#inherit(node) ⇒ Object

Kill the affiliations node before running inherit



26
27
28
29
# File 'lib/blather/stanza/pubsub/affiliations.rb', line 26

def inherit(node)
  affiliations.remove
  super
end

#listHash<String => Array<String>>

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

Examples:


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

Returns:

  • (Hash<String => Array<String>>)


67
68
69
70
71
72
73
74
# 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

#sizeFixnum

Get the number of affiliations

Returns:

  • (Fixnum)


52
53
54
# File 'lib/blather/stanza/pubsub/affiliations.rb', line 52

def size
  list.size
end