Sha256: bfe12db339e8f73f870fab9d214db6f7a7dc908cec0b2b9e851d52e7bac99928

Contents?: true

Size: 956 Bytes

Versions: 9

Compression:

Stored size: 956 Bytes

Contents

module Licensee
  class Project
    class Readme < LicenseFile
      SCORES = {
        /\AREADME\z/i                          => 1.0,
        /\AREADME\.(md|markdown|mdown|txt)\z/i => 0.9
      }.freeze

      CONTENT_REGEX = /^
          (?:\#+\sLicen[sc]e     # Start of hashes-based license header
             |
             Licen[sc]e\n[-=]+)$ # Start of underlined license header
          (.*?)                  # License content
          (?=^(?:\#+             # Next hashes-based header
                 |
                 [^\n]+\n[-=]+)  # Next of underlined header
             |
             \z)                 # End of file
        /mix

      def self.name_score(filename)
        SCORES.each do |pattern, score|
          return score if pattern =~ filename
        end
        0.0
      end

      def self.license_content(content)
        match = CONTENT_REGEX.match(content)
        match[1].strip if match
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
licensee-8.9.2 lib/licensee/project_files/readme.rb
licensee-8.9.0 lib/licensee/project_files/readme.rb
licensee-8.8.5 lib/licensee/project_files/readme.rb
licensee-8.8.4 lib/licensee/project_files/readme.rb
licensee-8.8.3 lib/licensee/project_files/readme.rb
licensee-8.8.2 lib/licensee/project_files/readme.rb
licensee-8.8.1 lib/licensee/project_files/readme.rb
licensee-8.8.0 lib/licensee/project_files/readme.rb
licensee-8.7.0 lib/licensee/project_files/readme.rb