Sha256: 443581a6b031c11e0203a5273bb5c93134adab250b92c18fda021d3373d6ee1e

Contents?: true

Size: 505 Bytes

Versions: 4

Compression:

Stored size: 505 Bytes

Contents

require 'cgi'

module RubyAMI
  class AsyncAGIEnvironmentParser
    def initialize(environment_string)
      @environment_string = environment_string.dup
    end

    def to_hash
      to_array.inject({}) do |accumulator, element|
        accumulator[element[0].to_sym] = element[1] || ''
        accumulator
      end
    end

    def to_s
      @environment_string.dup
    end

    private

    def to_array
      CGI.unescape(@environment_string).split("\n").map { |p| p.split ': ' }
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ruby_ami-1.2.3 lib/ruby_ami/async_agi_environment_parser.rb
ruby_ami-1.2.2 lib/ruby_ami/async_agi_environment_parser.rb
ruby_ami-1.2.1 lib/ruby_ami/async_agi_environment_parser.rb
ruby_ami-1.2.0 lib/ruby_ami/async_agi_environment_parser.rb