Class: Blather::Stanza::X::Field::Option

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

Overview

Option stanza fragment

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(value, label = nil) ⇒ Object

Create a new X Field Option

Overloads:

  • .new(node) ⇒ Object

    Imports the XML::Node to create a Field option object

    Parameters:

    • node (XML::Node)

      the node object to import

  • .new(opts = {}) ⇒ Object

    Creates a new Field option using a hash of options

    Parameters:

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

      a hash of options

    Options Hash (opts):

    • :value (String)

      the value of the field option

    • :label (String)

      the human readable label for the field option

  • .new(value, label = nil) ⇒ Object

    Create a new Field option by name

    Parameters:

    • value (String)

      the value of the field option

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

      the human readable label for the field option



363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
# File 'lib/blather/stanza/x.rb', line 363

def self.new(value, label = nil)
  new_node = super :option

  case value
  when Nokogiri::XML::Node
    new_node.inherit value
  when Hash
    new_node.value = value[:value]
    new_node.label = value[:label]
  else
    new_node.value = value
    new_node.label = label
  end
  new_node
end

Instance Method Details

#labelString

The Field Option’s label

Returns:

  • (String)


402
403
404
# File 'lib/blather/stanza/x.rb', line 402

def label
  read_attr :label
end

#label=(label) ⇒ Object

Set the Field Option’s label

Parameters:

  • label (String)

    the new label for the field option



408
409
410
# File 'lib/blather/stanza/x.rb', line 408

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

#valueString

The Field Option’s value

Returns:

  • (String)


381
382
383
384
385
386
387
# File 'lib/blather/stanza/x.rb', line 381

def value
  if self.namespace
    content_from 'ns:value', :ns => self.namespace.href
  else
    content_from :value
  end
end

#value=(value) ⇒ Object

Set the Field Option’s value

Parameters:

  • value (String)

    the new value for the field option



391
392
393
394
395
396
397
398
# File 'lib/blather/stanza/x.rb', line 391

def value=(value)
  self.remove_children :value
  if value
    self << (v = XMPPNode.new(:value))
    v.namespace = self.namespace
    v << value
  end
end