Class: Blather::Stanza::PubSub::Affiliations
- Inherits:
-
Blather::Stanza::PubSub
- Object
- Nokogiri::XML::Node
- XMPPNode
- Blather::Stanza
- Iq
- Blather::Stanza::PubSub
- Blather::Stanza::PubSub::Affiliations
- 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
Constants inherited from XMPPNode
Class Method Summary collapse
-
.new(type = nil, host = nil) ⇒ Object
Overrides the parent to ensure an affiliation node is created.
Instance Method Summary collapse
-
#affiliations ⇒ Blather::XMPPNode
Get or create the affiliations node.
-
#each(&block) ⇒ Object
Convenience method for iterating over the list.
-
#inherit(node) ⇒ Object
Kill the affiliations node before running inherit.
-
#list ⇒ Hash<String => Array<String>>
Get the hash of affilations as affiliation-type => [nodes].
-
#size ⇒ Fixnum
Get the number of affiliations.
Methods inherited from Blather::Stanza::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=, next_id, register, #reply, #reply!, #to, #to=, #type, #type=
Methods inherited from XMPPNode
class_from_registration, #content_from, import, #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(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
#affiliations ⇒ Blather::XMPPNode
Get or create the affiliations node
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 |
#list ⇒ Hash<String => Array<String>>
Get the hash of affilations as affiliation-type => [nodes]
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 |
#size ⇒ Fixnum
Get the number of affiliations
52 53 54 |
# File 'lib/blather/stanza/pubsub/affiliations.rb', line 52 def size list.size end |