Class: RCAP::Base::Parameter

Inherits:
Object
  • Object
show all
Includes:
Validation
Defined in:
lib/rcap/base/parameter.rb

Direct Known Subclasses

EventCode, Geocode, CAP_1_0::Parameter, CAP_1_1::Parameter, CAP_1_2::Parameter

Constant Summary

XML_ELEMENT_NAME =
"parameter"
NAME_ELEMENT_NAME =
"valueName"
VALUE_ELEMENT_NAME =
"value"
XPATH =
"cap:#{ XML_ELEMENT_NAME }"
NAME_XPATH =
"cap:#{ NAME_ELEMENT_NAME }"
VALUE_XPATH =
"cap:#{ VALUE_ELEMENT_NAME }"

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Parameter) initialize {|_self| ... }

A new instance of Parameter

Parameters:

  • attributes (Hash)

Yields:

  • (_self)

Yield Parameters:



24
25
26
# File 'lib/rcap/base/parameter.rb', line 24

def initialize
  yield( self ) if block_given?
end

Instance Attribute Details

- (String) name

Returns:



9
10
11
# File 'lib/rcap/base/parameter.rb', line 9

def name
  @name
end

- (String) value

Returns:



11
12
13
# File 'lib/rcap/base/parameter.rb', line 11

def value
  @value
end

Class Method Details

+ (Parameter) from_h(hash)

Parameters:

  • hash (Hash)

Returns:



78
79
80
81
82
83
84
# File 'lib/rcap/base/parameter.rb', line 78

def self.from_h( hash )
  key = hash.keys.first
  self.new do |parameter|
    parameter.name  = RCAP.strip_if_given( key )
    parameter.value = RCAP.strip_if_given( hash[ key ])
  end
end

+ (Parameter) from_xml_element(parameter_xml_element)

Parameters:

  • parameter_xml_element (REXML::Element)

Returns:



64
65
66
67
68
69
# File 'lib/rcap/base/parameter.rb', line 64

def self.from_xml_element( parameter_xml_element )
  self.new do |parameter|
     parameter.name  = RCAP.xpath_text( parameter_xml_element, self::NAME_XPATH, parameter.xmlns )
     parameter.value = RCAP.xpath_text( parameter_xml_element, self::VALUE_XPATH, parameter.xmlns )
  end
end

Instance Method Details

- (true, false) ==(other)

Two parameters are equivalent if they have the same name and value.

Parameters:

Returns:

  • (true, false)


58
59
60
# File 'lib/rcap/base/parameter.rb', line 58

def ==( other )
  [ @name, @value ] == [ other.name, other.value ]
end

- (String) inspect

Returns:



42
43
44
# File 'lib/rcap/base/parameter.rb', line 42

def inspect
  "#{ @name }: #{ @value }"
end

- (Hash) to_h

Returns:

  • (Hash)


72
73
74
# File 'lib/rcap/base/parameter.rb', line 72

def to_h
  RCAP.attribute_values_to_hash( [ @name, @value ])
end

- (String) to_s

Returns a string representation of the parameter of the form

name: value

Returns:



50
51
52
# File 'lib/rcap/base/parameter.rb', line 50

def to_s
  self.inspect
end

- (String) to_xml

Returns:



37
38
39
# File 'lib/rcap/base/parameter.rb', line 37

def to_xml
  self.to_xml_element.to_s
end

- (REXML::Element) to_xml_element

Returns:

  • (REXML::Element)


29
30
31
32
33
34
# File 'lib/rcap/base/parameter.rb', line 29

def to_xml_element
  xml_element = REXML::Element.new( self.class::XML_ELEMENT_NAME )
  xml_element.add_element( self.class::NAME_ELEMENT_NAME ).add_text( @name )
  xml_element.add_element( self.class::VALUE_ELEMENT_NAME ).add_text( @value )
  xml_element
end