Class: Blather::Stanza::Iq::Roster::RosterItem
- Inherits:
-
XMPPNode
- Object
- Niceogiri::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, groups = 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, #decorate, decorator_modules, import, parse, register
Class Method Details
.new(XML: :Node) ⇒ Object .new(opts) ⇒ Object .new(jid = nil, name = nil, subscription = nil, ask = nil) ⇒ Object
Create a new RosterItem
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/blather/stanza/iq/roster.rb', line 75 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 |
Instance Method Details
#ask ⇒ <:subscribe, nil>
Get the ask value of the item
142 143 144 |
# File 'lib/blather/stanza/iq/roster.rb', line 142 def ask read_attr :ask, :to_sym end |
#ask=(ask) ⇒ Object
Set the ask value of the item
149 150 151 |
# File 'lib/blather/stanza/iq/roster.rb', line 149 def ask=(ask) write_attr :ask, ask end |
#groups ⇒ Array<String>
The groups roster item belongs to
156 157 158 |
# File 'lib/blather/stanza/iq/roster.rb', line 156 def groups find('child::*[local-name()="group"]').map { |g| g.content } end |
#groups=(new_groups) ⇒ Object
Set the roster item’s groups
163 164 165 166 167 168 169 170 171 |
# File 'lib/blather/stanza/iq/roster.rb', line 163 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
100 101 102 |
# File 'lib/blather/stanza/iq/roster.rb', line 100 def jid (j = self[:jid]) ? JID.new(j) : nil end |
#jid=(jid) ⇒ Object
Set the JID of the item
107 108 109 |
# File 'lib/blather/stanza/iq/roster.rb', line 107 def jid=(jid) write_attr :jid, (jid.nil?) ? nil : JID.new(jid).stripped end |
#name ⇒ String?
Get the item name
114 115 116 |
# File 'lib/blather/stanza/iq/roster.rb', line 114 def name read_attr :name end |
#name=(name) ⇒ Object
Set the item name
121 122 123 |
# File 'lib/blather/stanza/iq/roster.rb', line 121 def name=(name) write_attr :name, name end |
#subscription ⇒ <:both, :from, :none, :remove, :to>
Get the subscription value of the item
128 129 130 |
# File 'lib/blather/stanza/iq/roster.rb', line 128 def subscription read_attr :subscription, :to_sym end |
#subscription=(subscription) ⇒ Object
Set the subscription value of the item
135 136 137 |
# File 'lib/blather/stanza/iq/roster.rb', line 135 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
177 178 179 |
# File 'lib/blather/stanza/iq/roster.rb', line 177 def to_stanza Roster.new(:set, self) end |