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

Inherits:
XMPPNode 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, #content_from, import, #inherit, #inherit_attrs, #inspect, #namespace=, #namespace_href, #nokogiri_namespace=, #read_attr, #read_content, register, #remove_child, #remove_children, #set_content_for, #to_stanza, #write_attr

Methods inherited from Nokogiri::XML::Node

#[]=, #attr_set, #find_first, #nokogiri_xpath, #xpath

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) ⇒ Boolean Also known as: ==

Check for equality based on jid, node, and name

Parameters:

Returns:

  • (Boolean)


127
128
129
130
131
132
133
134
135
# File 'lib/blather/stanza/disco/disco_items.rb', line 127

def eql?(o)
  unless o.is_a?(self.class)
    raise "Cannot compare #{self.class} with #{o.class}"
  end

  o.jid == self.jid &&
  o.node == self.node &&
  o.name == self.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