Class: Blather::Stanza::DiscoItems::Item

Inherits:
XMPPNode
  • Object
show all
Defined in:
lib/blather/stanza/disco/disco_items.rb

Overview

An individual Disco Item

Constant Summary

Constants inherited from XMPPNode

XMPPNode::BASE_NAMES

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from XMPPNode

class_from_registration, #decorate, decorator_modules, import, parse, register, #to_stanza

Class Method Details

.new(node) ⇒ Object .new(opts) ⇒ Object .new(jid, node = nil, name = nil) ⇒ Object

Create a new Blather::Stanza::DiscoItems::Item

Overloads:

  • .new(node) ⇒ Object

    Create a new Item by inheriting an existing node

    Parameters:

    • node (XML::Node)

      an XML::Node to inherit from

  • .new(opts) ⇒ Object

    Create a new Item through a hash of options

    Parameters:

    • opts (Hash)

      a hash options

    Options Hash (opts):

    • :jid (Blather::JID, String)

      the JID to attach to the item

    • :node (#to_s)

      the node the item is attached to

    • :name (#to_S)

      the name of the Item

  • .new(jid, node = nil, name = nil) ⇒ Object

    Create a new Item

    Parameters:

    • jid (Blather::JID, String)

      the JID to attach to the item

    • node (#to_s) (defaults to: nil)

      the node the item is attached to

    • name (#to_s) (defaults to: nil)

      the name of the Item



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/blather/stanza/disco/disco_items.rb', line 64

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

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

Instance Method Details

#eql?(o, *fields) ⇒ true, false

Compare two DiscoItems::Item objects by name, type and category

Parameters:

Returns:

  • (true, false)


127
128
129
# File 'lib/blather/stanza/disco/disco_items.rb', line 127

def eql?(o, *fields)
  super o, *(fields + [:jid, :node, :name])
end

#jidBlather::JID?

Get the JID attached to the node

Returns:



85
86
87
# File 'lib/blather/stanza/disco/disco_items.rb', line 85

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

#jid=(jid) ⇒ Object

Set the JID of the node

Parameters:



92
93
94
# File 'lib/blather/stanza/disco/disco_items.rb', line 92

def jid=(jid)
  write_attr :jid, jid
end

#nameString?

Get the Item name

Returns:

  • (String, nil)


113
114
115
# File 'lib/blather/stanza/disco/disco_items.rb', line 113

def name
  read_attr :name
end

#name=(name) ⇒ Object

Set the Item name

Parameters:

  • name (#to_s)

    the Item name



120
121
122
# File 'lib/blather/stanza/disco/disco_items.rb', line 120

def name=(name)
  write_attr :name, name
end

#nodeString?

Get the name of the node

Returns:

  • (String, nil)


99
100
101
# File 'lib/blather/stanza/disco/disco_items.rb', line 99

def node
  read_attr :node
end

#node=(node) ⇒ Object

Set the name of the node

Parameters:

  • node (String, nil)

    the new node name



106
107
108
# File 'lib/blather/stanza/disco/disco_items.rb', line 106

def node=(node)
  write_attr :node, node
end