Sha256: 8442cecbee0bf515a97e651bb9edb0d1571aba1c4f975789254719e18bfa7b96

Contents?: true

Size: 1.1 KB

Versions: 5

Compression:

Stored size: 1.1 KB

Contents

module RCAP
  module CAP_1_0
    # A Parameter object is valid if
    # * it has a name
    # * it has a value
    class Parameter < RCAP::Base::Parameter

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

      # @param [REXML::Element] parameter_xml_element
      # @return [Parameter]
      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

      # @param [String] parameter_string
      # @return [Hash]
      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
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rcap-2.4.1 lib/rcap/cap_1_0/parameter.rb
rcap-2.4.0 lib/rcap/cap_1_0/parameter.rb
rcap-2.3.0 lib/rcap/cap_1_0/parameter.rb
rcap-2.2.1 lib/rcap/cap_1_0/parameter.rb
rcap-2.2.0 lib/rcap/cap_1_0/parameter.rb