Class: RCAP::CAP_1_0::Parameter

Inherits:
Base::Parameter show all
Defined in:
lib/rcap/cap_1_0/parameter.rb

Overview

A Parameter object is valid if

  • it has a name

  • it has a value

Constant Summary

Constant Summary

Constants inherited from Base::Parameter

Base::Parameter::NAME_ELEMENT_NAME, Base::Parameter::NAME_XPATH, Base::Parameter::VALUE_ELEMENT_NAME, Base::Parameter::VALUE_XPATH, Base::Parameter::XML_ELEMENT_NAME, Base::Parameter::XPATH

Instance Attribute Summary

Attributes inherited from Base::Parameter

#name, #value

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from Base::Parameter

#==, from_h, #initialize, #inspect, #to_h, #to_s, #to_xml

Constructor Details

This class inherits a constructor from RCAP::Base::Parameter

Class Method Details

+ (Parameter) from_xml_element(parameter_xml_element)

Parameters:

  • parameter_xml_element (REXML::Element)

Returns:



17
18
19
20
21
22
23
# File 'lib/rcap/cap_1_0/parameter.rb', line 17

def self.from_xml_element( parameter_xml_element )
  parameter_hash = self.parse_parameter( parameter_xml_element.text )
  self.new do |parameter|
    parameter.name   = RCAP.strip_if_given( parameter_hash[ :name ])
    parameter.value  = RCAP.strip_if_given( parameter_hash[ :value ])
  end
end

+ (Hash) parse_parameter(parameter_string)

Parameters:

Returns:

  • (Hash)


27
28
29
30
31
32
33
# File 'lib/rcap/cap_1_0/parameter.rb', line 27

def self.parse_parameter( parameter_string )
  name, value = parameter_string.split("=")
  if name && value
    { :name  => RCAP.strip_if_given( name ),
      :value => RCAP.strip_if_given( value )}
  end
end

Instance Method Details

- (REXML::Element) to_xml_element

Returns:

  • (REXML::Element)


9
10
11
12
13
# File 'lib/rcap/cap_1_0/parameter.rb', line 9

def to_xml_element
  xml_element = REXML::Element.new( self.class::XML_ELEMENT_NAME )
  xml_element.add_text( "#{ @name }=#{ @value }")
  xml_element
end