Sha256: a4a39bcf7f0f2291f1130c7fe2eb4e42e576238f6fa673272680e5f248793b59

Contents?: true

Size: 1.01 KB

Versions: 4

Compression:

Stored size: 1.01 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 = parameter_hash[ :name ]
          parameter.value  = 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  => name,
            :value => value }
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rcap-2.1.0 lib/rcap/cap_1_0/parameter.rb
rcap-2.0.2 lib/rcap/cap_1_0/parameter.rb
rcap-2.0.1 lib/rcap/cap_1_0/parameter.rb
rcap-2.0.0 lib/rcap/cap_1_0/parameter.rb