Class: Blather::Stanza::Iq::Roster::RosterItem

Inherits:
XMPPNode show all
Defined in:
lib/blather/stanza/iq/roster.rb

Constant Summary

Constants inherited from XMPPNode

XMPPNode::BASE_NAMES

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from XMPPNode

attribute_accessor, attribute_reader, attribute_writer, class_from_registration, content_attr_accessor, content_attr_reader, content_attr_writer, #content_from, import, #inherit, #inherit_attrs, #namespace=, #namespace_href, #nokogiri_namespace=, register, #remove_child, #remove_children, #set_content_for

Methods inherited from Nokogiri::XML::Node

#[]=, #attr_set, #find_first, #nokogiri_xpath, #xpath

Class Method Details

.new(jid = nil, name = nil, subscription = nil, ask = nil) ⇒ Object

jid

may be either a JID or XMPPNode.

name

name alias of the given JID

subscription

subscription type

ask

ask subscription sub-state



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/blather/stanza/iq/roster.rb', line 40

def self.new(jid = nil, name = nil, subscription = nil, ask = nil)
  new_node = super :item

  case jid
  when Nokogiri::XML::Node
    new_node.inherit jid
  when Hash
    new_node.jid = jid[:jid]
    new_node.name = jid[:name]
    new_node.subscription = jid[:subscription]
    new_node.ask = jid[:ask]
  else
    new_node.jid = jid
    new_node.name = name
    new_node.subscription = subscription
    new_node.ask = ask
  end
  new_node
end

Instance Method Details

#groupsObject

The groups roster item belongs to



73
74
75
# File 'lib/blather/stanza/iq/roster.rb', line 73

def groups
  find('child::*[local-name()="group"]').map { |g| g.content }
end

#groups=(new_groups) ⇒ Object

Set the roster item’s groups must be an array



80
81
82
83
84
85
86
87
88
# File 'lib/blather/stanza/iq/roster.rb', line 80

def groups=(new_groups)
  remove_children :group
  if new_groups
    new_groups.uniq.each do |g|
      self << (group = XMPPNode.new(:group, self.document))
      group.content = g
    end
  end
end

#jidObject

Roster item’s JID



62
63
64
# File 'lib/blather/stanza/iq/roster.rb', line 62

def jid
  (j = self[:jid]) ? JID.new(j) : nil
end

#to_stanzaObject

Convert the roster item to a proper stanza all wrapped up This facilitates new subscriptions



93
94
95
# File 'lib/blather/stanza/iq/roster.rb', line 93

def to_stanza
  Roster.new(:set, self)
end