Class: Blather::Stanza::DiscoInfo

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

Overview

# DiscoInfo Stanza

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

Disco Info node that provides or retreives information about a jabber entity

Defined Under Namespace

Classes: Feature, Identity

Constant Summary

Constants inherited from Iq

Iq::VALID_TYPES

Constants inherited from XMPPNode

XMPPNode::BASE_NAMES

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Disco

#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=, next_id, register, #reply, #reply!, #to, #to=, #type, #type=

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(type = nil, node = nil, identities = [], features = []) ⇒ DiscoInfo

Create a new DiscoInfo stanza identities. these are passed directly to DiscoInfo::Identity.new features. these are passed directly to DiscoInfo::Feature.new

Parameters:

  • type (:get, :set, :result, :error, nil) (defaults to: nil)

    the Iq stanza type

  • node (String, nil) (defaults to: nil)

    the name of the node the info belongs to

  • identities (Array<Array, DiscoInfo::Identity>, nil) (defaults to: [])

    a list of

  • features (Array<Array, DiscoInfo::Identity>, nil) (defaults to: [])

    a list of

Returns:



22
23
24
25
26
27
28
# File 'lib/blather/stanza/disco/disco_info.rb', line 22

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

Instance Method Details

#featuresObject

List of feature objects



47
48
49
50
51
# File 'lib/blather/stanza/disco/disco_info.rb', line 47

def features
  query.find('//ns:feature', :ns => self.class.registered_ns).map do |f|
    Feature.new f
  end
end

#features=(features) ⇒ Object

Add an array of features

Parameters:

  • features

    the array of features, passed directly to Feature.new



55
56
57
58
59
60
# File 'lib/blather/stanza/disco/disco_info.rb', line 55

def features=(features)
  query.find('//ns:feature', :ns => self.class.registered_ns).each &:remove
  if features
    [features].flatten.each { |f| self.query << Feature.new(f) }
  end
end

#identitiesObject

List of identity objects



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

def identities
  query.find('//ns:identity', :ns => self.class.registered_ns).map do |i|
    Identity.new i
  end
end

#identities=(identities) ⇒ Object

Add an array of identities

Parameters:

  • identities

    the array of identities, passed directly to Identity.new



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

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