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

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

Overview

DiscoInfo::Identity

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(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



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/blather/stanza/disco/disco_info.rb', line 86

def self.new(name, type = nil, category = nil, xml_lang = 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]
    new_node.xml_lang = name[:xml_lang]
  else
    new_node.name = name
    new_node.type = type
    new_node.category = category
    new_node.xml_lang = xml_lang
  end
  new_node
end

Instance Method Details

#categorySymbol?

The Identity’s category

Returns:

  • (Symbol, nil)


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

def category
  read_attr :category, :to_sym
end

#category=(category) ⇒ Object

Set the Identity’s category

Parameters:

  • category (String, Symbol)

    the new category



114
115
116
# File 'lib/blather/stanza/disco/disco_info.rb', line 114

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

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

Compare two Identity objects by name, type and category

Parameters:

Returns:

  • (true, false)


157
158
159
# File 'lib/blather/stanza/disco/disco_info.rb', line 157

def eql?(o, *fields)
  super o, *(fields + [:name, :type, :category, :xml_lang])
end

#nameString

The Identity’s name

Returns:

  • (String)


132
133
134
# File 'lib/blather/stanza/disco/disco_info.rb', line 132

def name
  read_attr :name
end

#name=(name) ⇒ Object

Set the Identity’s name

Parameters:

  • name (String)

    the new name for the identity



138
139
140
# File 'lib/blather/stanza/disco/disco_info.rb', line 138

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

#typeSymbol?

The Identity’s type

Returns:

  • (Symbol, nil)


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

def type
  read_attr :type, :to_sym
end

#type=(type) ⇒ Object

Set the Identity’s type

Parameters:

  • type (String, Symbol)

    the new category



126
127
128
# File 'lib/blather/stanza/disco/disco_info.rb', line 126

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

#xml_langString

The Identity’s xml_lang

Returns:

  • (String)


144
145
146
# File 'lib/blather/stanza/disco/disco_info.rb', line 144

def xml_lang
  read_attr "lang"
end

#xml_lang=(xml_lang) ⇒ Object

Set the Identity’s name

Parameters:

  • name (String)

    the new name for the identity



150
151
152
# File 'lib/blather/stanza/disco/disco_info.rb', line 150

def xml_lang=(xml_lang)
  write_attr "xml:lang", xml_lang
end