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
105
106
# File 'lib/blather/stanza/disco/disco_info.rb', line 86

def self.new(name, type = nil, category = nil, xml_lang = nil)
  return name if name.class == self

  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)


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

def category
  read_attr :category, :to_sym
end

#category=(category) ⇒ Object

Set the Identity’s category

Parameters:

  • category (String, Symbol)

    the new category



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

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)


159
160
161
# File 'lib/blather/stanza/disco/disco_info.rb', line 159

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

#nameString

The Identity’s name

Returns:

  • (String)


134
135
136
# File 'lib/blather/stanza/disco/disco_info.rb', line 134

def name
  read_attr :name
end

#name=(name) ⇒ Object

Set the Identity’s name

Parameters:

  • name (String)

    the new name for the identity



140
141
142
# File 'lib/blather/stanza/disco/disco_info.rb', line 140

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

#typeSymbol?

The Identity’s type

Returns:

  • (Symbol, nil)


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

def type
  read_attr :type, :to_sym
end

#type=(type) ⇒ Object

Set the Identity’s type

Parameters:

  • type (String, Symbol)

    the new category



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

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

#xml_langString

The Identity’s xml_lang

Returns:

  • (String)


146
147
148
# File 'lib/blather/stanza/disco/disco_info.rb', line 146

def xml_lang
  read_attr "xml:lang"
end

#xml_lang=(xml_lang) ⇒ Object

Set the Identity’s name

Parameters:

  • name (String)

    the new name for the identity



152
153
154
# File 'lib/blather/stanza/disco/disco_info.rb', line 152

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