class Blather::Stanza::Iq::Roster::RosterItem
# RosterItem
Fragment
Individual roster items. This is a convenience class to attach methods to the node
Public Class Methods
Create a new RosterItem
@overload new(XML::Node)
Create a RosterItem by inheriting a node @param [XML::Node] node an xml node to inherit
@overload new(opts)
Create a RosterItem through a hash of options @param [Hash] opts the options @option opts [Blather::JID, String, nil] :jid the JID of the item @option opts [String, nil] :name the alias to give the JID @option opts [Symbol, nil] :subscription the subscription status of the RosterItem must be one of Blather::RosterItem::VALID_SUBSCRIPTION_TYPES @option opts [:subscribe, nil] :ask the ask value of the RosterItem @option opts [Array<#to_s>] :groups the group names the RosterItem is a member of
@overload new(jid = nil, name = nil, subscription = nil, ask = nil)
@param [Blather::JID, String, nil] jid the JID of the item @param [String, nil] name the alias to give the JID @param [Symbol, nil] subscription the subscription status of the RosterItem must be one of Blather::RosterItem::VALID_SUBSCRIPTION_TYPES @param [:subscribe, nil] ask the ask value of the RosterItem @param [Array<#to_s>] groups the group names the RosterItem is a member of
# File lib/blather/stanza/iq/roster.rb, line 82 def self.new(jid = nil, name = nil, subscription = nil, ask = nil, groups = 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] new_node.groups = jid[:groups] else new_node.jid = jid new_node.name = name new_node.subscription = subscription new_node.ask = ask new_node.groups = groups end new_node end
Public Instance Methods
Get the ask value of the item
@return [<:subscribe, nil>]
# File lib/blather/stanza/iq/roster.rb, line 149 def ask read_attr :ask, :to_sym end
Set the ask value of the item
@param [<:subscribe, nil>] ask
# File lib/blather/stanza/iq/roster.rb, line 156 def ask=(ask) write_attr :ask, ask end
The groups roster item belongs to
@return [Array<String>]
# File lib/blather/stanza/iq/roster.rb, line 163 def groups find('child::*[local-name()="group"]').map { |g| g.content } end
Set the roster item's groups
@param [Array<#to_s>] new_groups an array of group names
# File lib/blather/stanza/iq/roster.rb, line 170 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
Get the JID
attached to the item
@return [Blather::JID, nil]
# File lib/blather/stanza/iq/roster.rb, line 107 def jid (j = self[:jid]) ? JID.new(j) : nil end
Get the item name
@return [String, nil]
# File lib/blather/stanza/iq/roster.rb, line 121 def name read_attr :name end
Set the item name
@param [#to_s] name the name of the item
# File lib/blather/stanza/iq/roster.rb, line 128 def name=(name) write_attr :name, name end
Get the subscription value of the item
@return [<:both, :from, :none, :remove, :to>]
# File lib/blather/stanza/iq/roster.rb, line 135 def subscription read_attr :subscription, :to_sym end
Set the subscription value of the item
@param [<:both, :from, :none, :remove, :to>] subscription
# File lib/blather/stanza/iq/roster.rb, line 142 def subscription=(subscription) write_attr :subscription, subscription end
Convert the roster item to a proper stanza all wrapped up This facilitates new subscriptions
@return [Blather::Stanza::Iq::Roster]
# File lib/blather/stanza/iq/roster.rb, line 184 def to_stanza Roster.new(:set, self) end