Class: Jabber::Version::IqQueryVersion

Inherits:
IqQuery show all
Defined in:
lib/xmpp4r/version/iq/version.rb

Overview

Class for handling queries for 'Software Version' (JEP 0092)

Notice that according to JEP 0092 only the <os/> element can be omitted, <name/> (iname) and <version/> must be present

Instance Method Summary collapse

Methods inherited from IqQuery

add_namespaceclass, import

Methods inherited from REXML::Element

#delete_elements, #first_element, #first_element_text, import, #replace_element_text, #typed_add

Constructor Details

#initialize(iname = '', version = '', os = nil) ⇒ IqQueryVersion

Create a new <query xmlns='jabber:iq:version'/> element



18
19
20
21
22
23
24
# File 'lib/xmpp4r/version/iq/version.rb', line 18

def initialize(iname='', version='', os=nil)
  super()
  add_namespace('jabber:iq:version')
  set_iname(iname)
  set_version(version)
  set_os(os)
end

Instance Method Details

#import(xe) ⇒ Object

Import an element, deletes <name/>, <version/> and <os/> elements first

xe
REXML::Element


30
31
32
33
34
35
# File 'lib/xmpp4r/version/iq/version.rb', line 30

def import(xe)
  delete_element('name')
  delete_element('version')
  delete_element('os')
  super
end

#inameObject

Get the name of the software

This has been renamed to 'iname' here to keep REXML::Element#name accessible



42
43
44
# File 'lib/xmpp4r/version/iq/version.rb', line 42

def iname
  first_element_text('name')
end

#iname=(text) ⇒ Object

Set the name of the software

The element won't be deleted if text is nil as it must occur in a version query, but its text will be empty.



52
53
54
# File 'lib/xmpp4r/version/iq/version.rb', line 52

def iname=(text)
  replace_element_text('name', text.nil? ? '' : text)
end

#osObject

Get the operating system or nil (os is not mandatory for Version Query)



91
92
93
# File 'lib/xmpp4r/version/iq/version.rb', line 91

def os
  first_element_text('os')
end

#os=(text) ⇒ Object

Set the os of the software

text
String

or nil



98
99
100
101
102
103
104
# File 'lib/xmpp4r/version/iq/version.rb', line 98

def os=(text)
  if text
    replace_element_text('os', text)
  else
    delete_elements('os')
  end
end

#set_iname(text) ⇒ Object

Set the name of the software (chaining-friendly)

result
String

or nil



59
60
61
62
# File 'lib/xmpp4r/version/iq/version.rb', line 59

def set_iname(text)
  self.iname = text
  self
end

#set_os(text) ⇒ Object

Set the os of the software (chaining-friendly)

text
String

or nil



109
110
111
112
# File 'lib/xmpp4r/version/iq/version.rb', line 109

def set_os(text)
  self.os = text
  self
end

#set_version(text) ⇒ Object

Set the version of the software (chaining-friendly)

text
String


83
84
85
86
# File 'lib/xmpp4r/version/iq/version.rb', line 83

def set_version(text)
  self.version = text
  self
end

#versionObject

Get the version of the software

result
String

or nil



67
68
69
# File 'lib/xmpp4r/version/iq/version.rb', line 67

def version
  first_element_text('version')
end

#version=(text) ⇒ Object

Set the version of the software

The element won't be deleted if text is nil as it must occur in a version query



76
77
78
# File 'lib/xmpp4r/version/iq/version.rb', line 76

def version=(text)
  replace_element_text('version', text.nil? ? '' : text)
end