Sha256: f56783c1421afee7ba5fed385dd9c3c71e06082addb608479a547bf72675a8d0

Contents?: true

Size: 877 Bytes

Versions: 1

Compression:

Stored size: 877 Bytes

Contents

require 'natives/catalog/normalizer'

module Natives
  class Catalog
    class Selector
      def initialize(hash)
        @values = normalize(hash)
      end

      def values_for(package_provider, platform, platform_version)
        package_provider = package_provider.to_s
        platform = platform.to_s
        platform_version = platform_version.to_s

        values = nil
        platforms = @values.fetch(package_provider, nil)
        if platforms
          versions  = platforms.fetch(platform, nil)
          if versions
            values = versions.fetch(platform_version, nil) ||
              versions.fetch('default', nil)
          else
            values = platforms.fetch('default', nil)
          end
        end

        Array(values)
      end

      private

      def normalize(hash)
        Normalizer.new.normalize(hash)
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
natives-0.6.0 lib/natives/catalog/selector.rb