Sha256: 53c466270e8daa2c074ad9c611e46f1373c7a43e150136aa12618bb34859881d

Contents?: true

Size: 701 Bytes

Versions: 16

Compression:

Stored size: 701 Bytes

Contents

# encoding: utf-8
# author: Dominik Richter
# author: Christoph Hartmann

class HashMap
  class << self
    def [](hash, *keys)
      return hash if keys.empty? || hash.nil?
      key = keys.shift
      if hash.is_a?(Array)
        map = hash.map { |i| [i, key] }
      else
        map = hash[key]
      end
      [map, *keys]
    rescue NoMethodError => _
      nil
    end
  end
end

class StringMap
  class << self
    def [](hash, *keys)
      return hash if keys.empty? || hash.nil?
      key = keys.shift
      if hash.is_a?(Array)
        map = hash.map { |i| [i, key] }
      else
        map = hash[key]
      end
      [map, *keys]
    rescue NoMethodError => _
      nil
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
inspec-0.30.0 lib/utils/hash_map.rb
inspec-0.28.0 lib/utils/hash_map.rb
inspec-0.27.1 lib/utils/hash_map.rb
inspec-0.24.0 lib/utils/hash_map.rb
inspec-0.21.6 lib/utils/hash_map.rb
inspec-0.21.5 lib/utils/hash_map.rb
inspec-0.21.4 lib/utils/hash_map.rb
inspec-0.20.0 lib/utils/hash_map.rb
inspec-0.19.1 lib/utils/hash_map.rb
inspec-0.19.0 lib/utils/hash_map.rb
inspec-0.17.1 lib/utils/hash_map.rb
inspec-0.17.0 lib/utils/hash_map.rb
inspec-0.16.4 lib/utils/hash_map.rb
inspec-0.16.3 lib/utils/hash_map.rb
inspec-0.16.2 lib/utils/hash_map.rb
inspec-0.16.1 lib/utils/hash_map.rb