Class: Blather::Stanza::Iq::Roster::RosterItem
- Inherits:
-
XMPPNode
- Object
- Nokogiri::XML::Node
- XMPPNode
- Blather::Stanza::Iq::Roster::RosterItem
- Defined in:
- lib/blather/stanza/iq/roster.rb
Overview
# RosterItem Fragment
Individual roster items. This is a convenience class to attach methods to the node
Constant Summary
Constants inherited from XMPPNode
Class Method Summary collapse
-
.new(jid = nil, name = nil, subscription = nil, ask = nil) ⇒ Object
Create a new RosterItem.
Instance Method Summary collapse
-
#ask ⇒ <:subscribe, nil>
Get the ask value of the item.
-
#ask=(ask) ⇒ Object
Set the ask value of the item.
-
#groups ⇒ Array<String>
The groups roster item belongs to.
-
#groups=(new_groups) ⇒ Object
Set the roster item’s groups.
-
#jid ⇒ Blather::JID?
Get the JID attached to the item.
-
#jid=(jid) ⇒ Object
Set the JID of the item.
-
#name ⇒ String?
Get the item name.
-
#name=(name) ⇒ Object
Set the item name.
-
#subscription ⇒ <:both, :from, :none, :remove, :to>
Get the subscription value of the item.
-
#subscription=(subscription) ⇒ Object
Set the subscription value of the item.
-
#to_stanza ⇒ Blather::Stanza::Iq::Roster
Convert the roster item to a proper stanza all wrapped up This facilitates new subscriptions.
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, #write_attr
Methods inherited from Nokogiri::XML::Node
#[]=, #attr_set, #find_first, #nokogiri_xpath, #xpath
Class Method Details
.new(XML: :Node) ⇒ Object .new(opts) ⇒ Object .new(jid = nil, name = nil, subscription = nil, ask = nil) ⇒ Object
Create a new RosterItem
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/blather/stanza/iq/roster.rb', line 71 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
#ask ⇒ <:subscribe, nil>
Get the ask value of the item
136 137 138 |
# File 'lib/blather/stanza/iq/roster.rb', line 136 def ask read_attr :ask, :to_sym end |
#ask=(ask) ⇒ Object
Set the ask value of the item
143 144 145 |
# File 'lib/blather/stanza/iq/roster.rb', line 143 def ask=(ask) write_attr :ask, ask end |
#groups ⇒ Array<String>
The groups roster item belongs to
150 151 152 |
# File 'lib/blather/stanza/iq/roster.rb', line 150 def groups find('child::*[local-name()="group"]').map { |g| g.content } end |
#groups=(new_groups) ⇒ Object
Set the roster item’s groups
157 158 159 160 161 162 163 164 165 |
# File 'lib/blather/stanza/iq/roster.rb', line 157 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 |
#jid ⇒ Blather::JID?
Get the JID attached to the item
94 95 96 |
# File 'lib/blather/stanza/iq/roster.rb', line 94 def jid (j = self[:jid]) ? JID.new(j) : nil end |
#jid=(jid) ⇒ Object
Set the JID of the item
101 102 103 |
# File 'lib/blather/stanza/iq/roster.rb', line 101 def jid=(jid) write_attr :jid, jid end |
#name ⇒ String?
Get the item name
108 109 110 |
# File 'lib/blather/stanza/iq/roster.rb', line 108 def name read_attr :name end |
#name=(name) ⇒ Object
Set the item name
115 116 117 |
# File 'lib/blather/stanza/iq/roster.rb', line 115 def name=(name) write_attr :name, name end |
#subscription ⇒ <:both, :from, :none, :remove, :to>
Get the subscription value of the item
122 123 124 |
# File 'lib/blather/stanza/iq/roster.rb', line 122 def subscription read_attr :subscription, :to_sym end |
#subscription=(subscription) ⇒ Object
Set the subscription value of the item
129 130 131 |
# File 'lib/blather/stanza/iq/roster.rb', line 129 def subscription=(subscription) write_attr :subscription, subscription end |
#to_stanza ⇒ Blather::Stanza::Iq::Roster
Convert the roster item to a proper stanza all wrapped up This facilitates new subscriptions
171 172 173 |
# File 'lib/blather/stanza/iq/roster.rb', line 171 def to_stanza Roster.new(:set, self) end |