require 'nerv/version'

class Nerv
  DEFAULT_SEPARATOR = '_'.freeze

  class << self
    def prefix(keys_prefix, separator = DEFAULT_SEPARATOR)
      regexp = /^#{keys_prefix}#{separator}/

      pairs = ENV.map { |k, v| [k.gsub(regexp, ''), v] if k =~ regexp }
                 .compact
                 .flatten

      Hash[*pairs]
    end

    def [](keys_prefix)
      prefix(keys_prefix)
    end
  end
end

require 'nerv/version'

class Nerv
  DEFAULT_SEPARATOR = '_'.freeze

  class << self
    def prefix(keys_prefix, separator = DEFAULT_SEPARATOR)
      regexp = /^#{keys_prefix}#{separator}/

      pairs = ENV.map { |k, v| [k.gsub(regexp, ''), v] if k =~ regexp }

      Hash[*pairs.compact.flatten]
    end

    def [](keys_prefix)
      prefix(keys_prefix)
    end
  end
end

Fix for Ruby 1.8 and etc.
Fix for Ruby 1.8 and etc.