Class: RCAP::Base::Parameter
- Inherits:
-
Object
- Object
- RCAP::Base::Parameter
show all
- Includes:
- Validation
- Defined in:
- lib/rcap/base/parameter.rb
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
24
25
26
|
# File 'lib/rcap/base/parameter.rb', line 24
def initialize
yield( self ) if block_given?
end
|
Instance Attribute Details
9
10
11
|
# File 'lib/rcap/base/parameter.rb', line 9
def name
@name
end
|
11
12
13
|
# File 'lib/rcap/base/parameter.rb', line 11
def value
@value
end
|
Class Method Details
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)
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.
58
59
60
|
# File 'lib/rcap/base/parameter.rb', line 58
def ==( other )
[ @name, @value ] == [ other.name, other.value ]
end
|
42
43
44
|
# File 'lib/rcap/base/parameter.rb', line 42
def inspect
"#{ @name }: #{ @value }"
end
|
- (Hash) to_h
72
73
74
|
# File 'lib/rcap/base/parameter.rb', line 72
def to_h
RCAP.attribute_values_to_hash( [ @name, @value ])
end
|
Returns a string representation of the parameter of the form
name: value
50
51
52
|
# File 'lib/rcap/base/parameter.rb', line 50
def to_s
self.inspect
end
|
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
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
|