Sha256: 2dab21b737538920b792075ddee15d25be2aadc8ec4a0c7d4d548be69986fb60

Contents?: true

Size: 1.43 KB

Versions: 8

Compression:

Stored size: 1.43 KB

Contents

module Licensee
  module ProjectFiles
    class ReadmeFile < Licensee::ProjectFiles::LicenseFile
      EXTENSIONS = %w[md markdown mdown txt rdoc].freeze
      SCORES = {
        /\AREADME\z/i                                       => 1.0,
        /\AREADME\.(#{Regexp.union(EXTENSIONS).source})\z/i => 0.9
      }.freeze

      TITLE_REGEX = /licen[sc]e:?/i
      UNDERLINE_REGEX = /\n[-=]+/m
      CONTENT_REGEX = /^
          (?:                                # Header lookbehind
            [\#=]+\s#{TITLE_REGEX}           # Start of hashes or rdoc header
          |
            #{TITLE_REGEX}#{UNDERLINE_REGEX} # Start of underlined header
          )$
          (.*?)                              # License content
          (?=^                               # Header or end of file lookahead
            (?:
              [\#=]+                         # Next hash or rdoc header
            |
              [^\n]+#{UNDERLINE_REGEX}       # Next of underlined header
            )
          |
            \z                               # End of file
          )
        /mix

      def possible_matchers
        super.push(Matchers::Reference)
      end

      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

8 entries across 8 versions & 1 rubygems

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