Class: Blather::Stanza::DiscoItems

Inherits:
Disco show all
Defined in:
lib/blather/stanza/disco/disco_items.rb

Overview

# DiscoItems Stanza

[XEP-0030 Disco Info](xmpp.org/extensions/xep-0030.html#items)

Disco Items node that provides or retreives items associated with a jabbery entity

Defined Under Namespace

Classes: Item

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 Disco

#eql?, #node, #node=

Methods inherited from Iq::Query

#inherit, #query

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, node = nil, items = []) ⇒ Blather::Stanza::DiscoItems

Create a new DiscoItems node

Parameters:

  • type (#to_s) (defaults to: nil)

    the IQ type

  • node (#to_s) (defaults to: nil)

    the node the items are associated with

  • items (Array<Blather::XMPPNode>) (defaults to: [])

    an array of Disco::Items

Returns:



21
22
23
24
25
26
# File 'lib/blather/stanza/disco/disco_items.rb', line 21

def self.new(type = nil, node = nil, items = [])
  new_node = super type
  new_node.node = node
  new_node.items = [items]
  new_node
end

Instance Method Details

#itemsArray<Blather::Stanza::DiscoItems::Item>

Set of items associated with the node



31
32
33
34
35
# File 'lib/blather/stanza/disco/disco_items.rb', line 31

def items
  query.find('//ns:item', :ns => self.class.registered_ns).map do |i|
    Item.new i
  end
end

#items=(items) ⇒ Object

Add an array of items

Parameters:

  • items

    the array of items, passed directly to Item.new



39
40
41
42
43
44
# File 'lib/blather/stanza/disco/disco_items.rb', line 39

def items=(items)
  query.find('//ns:item', :ns => self.class.registered_ns).each &:remove
  if items
    [items].flatten.each { |i| self.query << Item.new(i) }
  end
end