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

Inherits:
XMPPNode show all
Defined in:
lib/blather/stanza/x.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(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



345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
# File 'lib/blather/stanza/x.rb', line 345

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)


384
385
386
# File 'lib/blather/stanza/x.rb', line 384

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



390
391
392
# File 'lib/blather/stanza/x.rb', line 390

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

#valueString

The Field Option’s value

Returns:

  • (String)


363
364
365
366
367
368
369
# File 'lib/blather/stanza/x.rb', line 363

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



373
374
375
376
377
378
379
380
# File 'lib/blather/stanza/x.rb', line 373

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