Class: Blather::Stanza::DiscoInfo::Identity

Inherits:
XMPPNode show all
Defined in:
lib/blather/stanza/disco/disco_info.rb

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(name, type = nil, category = nil) ⇒ Object

Create a new DiscoInfo Identity

Overloads:

  • .new(node) ⇒ Object

    Imports the XML::Node to create a Identity object

    Parameters:

    • node (XML::Node)

      the node object to import

  • .new(opts = {}) ⇒ Object

    Creates a new Identity using a hash of options

    Parameters:

    • opts (Hash) (defaults to: {})

      a hash of options

    Options Hash (opts):

    • :name (String)

      the name of the identity

    • :type (String)

      the type of the identity

    • :category (String)

      the category of the identity

  • .new(name, type = nil, category = nil) ⇒ Object

    Create a new Identity by name

    Parameters:

    • name (String)

      the name of the Identity

    • type (String, nil) (defaults to: nil)

      the type of the Identity

    • category (String, nil) (defaults to: nil)

      the category of the Identity



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/blather/stanza/disco/disco_info.rb', line 78

def self.new(name, type = nil, category = nil)
  new_node = super :identity

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

Instance Method Details

#categorySymbol?

The Identity’s category

Returns:

  • (Symbol, nil)


98
99
100
# File 'lib/blather/stanza/disco/disco_info.rb', line 98

def category
  read_attr :category, :to_sym
end

#category=(category) ⇒ Object

Set the Identity’s category

Parameters:

  • category (String, Symbol)

    the new category



104
105
106
# File 'lib/blather/stanza/disco/disco_info.rb', line 104

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

#eql?(o) ⇒ true, false Also known as: ==

Compare two Identity objects by name, type and category

Parameters:

Returns:

  • (true, false)


135
136
137
138
139
140
141
142
143
# File 'lib/blather/stanza/disco/disco_info.rb', line 135

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

  o.name == self.name &&
  o.type == self.type &&
  o.category == self.category
end

#nameString

The Identity’s name

Returns:

  • (String)


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

def name
  read_attr :name
end

#name=(name) ⇒ Object

Set the Identity’s name

Parameters:

  • name (String)

    the new name for the identity



128
129
130
# File 'lib/blather/stanza/disco/disco_info.rb', line 128

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

#typeSymbol?

The Identity’s type

Returns:

  • (Symbol, nil)


110
111
112
# File 'lib/blather/stanza/disco/disco_info.rb', line 110

def type
  read_attr :type, :to_sym
end

#type=(type) ⇒ Object

Set the Identity’s type

Parameters:

  • type (String, Symbol)

    the new category



116
117
118
# File 'lib/blather/stanza/disco/disco_info.rb', line 116

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