Sha256: 4340485a2d14e6cde49ec77448bfb698d7b7d0f68fa26ebf193a001acab77320

Contents?: true

Size: 1.25 KB

Versions: 9

Compression:

Stored size: 1.25 KB

Contents

module Licensee
  module ProjectFiles
    class PackageManagerFile < Licensee::ProjectFiles::ProjectFile
      # Hash of Extension => [possible matchers]
      MATCHERS_EXTENSIONS = {
        '.gemspec' => [Matchers::Gemspec],
        '.json'    => [Matchers::NpmBower],
        '.cabal'   => [Matchers::Cabal]
      }.freeze

      # Hash of Filename => [possible matchers]
      FILENAMES_EXTENSIONS = {
        'DESCRIPTION'  => [Matchers::Cran],
        'dist.ini'     => [Matchers::DistZilla],
        'LICENSE.spdx' => [Matchers::Spdx],
        'Cargo.toml'   => [Matchers::Cargo]
      }.freeze

      FILENAMES_SCORES = {
        'package.json'     => 1.0,
        'LICENSE.spdx'     => 1.0,
        'Cargo.toml'       => 1.0,
        'DESCRIPTION'      => 0.9,
        'dist.ini'         => 0.8,
        'bower.json'       => 0.75,
        'elm-package.json' => 0.7
      }.freeze

      def possible_matchers
        MATCHERS_EXTENSIONS[extension] || FILENAMES_EXTENSIONS[filename] || []
      end

      def self.name_score(filename)
        return 1.0 if ['.gemspec', '.cabal'].include?(File.extname(filename))
        FILENAMES_SCORES[filename] || 0.0
      end

      private

      def extension
        @extension ||= File.extname(filename)
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
licensee-9.10.0 lib/licensee/project_files/package_manager_file.rb
licensee-9.9.4 lib/licensee/project_files/package_manager_file.rb
licensee-9.9.3 lib/licensee/project_files/package_manager_file.rb
licensee-9.9.2 lib/licensee/project_files/package_manager_file.rb
licensee-9.9.1 lib/licensee/project_files/package_manager_file.rb
licensee-9.9.0 lib/licensee/project_files/package_manager_file.rb
licensee-9.9.0.beta.3 lib/licensee/project_files/package_manager_file.rb
licensee-9.9.0.beta.2 lib/licensee/project_files/package_manager_file.rb
licensee-9.8.0 lib/licensee/project_files/package_manager_file.rb