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
81
82
# File 'lib/blather/stanza/disco/disco_items.rb', line 64

def self.new(jid, node = nil, name = nil)
  return jid if jid.class == self

  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)


129
130
131
# File 'lib/blather/stanza/disco/disco_items.rb', line 129

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

#jidBlather::JID?

Get the JID attached to the node

Returns:



87
88
89
# File 'lib/blather/stanza/disco/disco_items.rb', line 87

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

#jid=(jid) ⇒ Object

Set the JID of the node

Parameters:



94
95
96
# File 'lib/blather/stanza/disco/disco_items.rb', line 94

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

#nameString?

Get the Item name

Returns:

  • (String, nil)


115
116
117
# File 'lib/blather/stanza/disco/disco_items.rb', line 115

def name
  read_attr :name
end

#name=(name) ⇒ Object

Set the Item name

Parameters:

  • name (#to_s)

    the Item name



122
123
124
# File 'lib/blather/stanza/disco/disco_items.rb', line 122

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

#nodeString?

Get the name of the node

Returns:

  • (String, nil)


101
102
103
# File 'lib/blather/stanza/disco/disco_items.rb', line 101

def node
  read_attr :node
end

#node=(node) ⇒ Object

Set the name of the node

Parameters:

  • node (String, nil)

    the new node name



108
109
110
# File 'lib/blather/stanza/disco/disco_items.rb', line 108

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