Class: Licensee::ProjectFiles::ReadmeFile

Inherits:
LicenseFile show all
Defined in:
lib/licensee/project_files/readme_file.rb

Constant Summary collapse

EXTENSIONS =
%w[md markdown mdown txt rdoc rst].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}\s*[\#=]*  # 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

Constants inherited from LicenseFile

LicenseFile::ANY_EXT_REGEX, LicenseFile::CC_FALSE_POSITIVE_REGEX, LicenseFile::COPYING_REGEX, LicenseFile::FILENAME_REGEXES, LicenseFile::LICENSE_EXT_REGEX, LicenseFile::LICENSE_REGEX, LicenseFile::OFL_REGEX, LicenseFile::OTHER_EXT_REGEX, LicenseFile::PATENTS_REGEX, LicenseFile::PREFERRED_EXT, LicenseFile::PREFERRED_EXT_REGEX

Constants included from ContentHelper

ContentHelper::DIGEST, ContentHelper::END_OF_TERMS_REGEX, ContentHelper::NORMALIZATIONS, ContentHelper::REGEXES, ContentHelper::START_REGEX, ContentHelper::STRIP_METHODS, ContentHelper::VARIETAL_WORDS

Constants inherited from ProjectFile

ProjectFile::ENCODING, ProjectFile::ENCODING_OPTIONS, ProjectFile::HASH_METHODS

Instance Attribute Summary

Attributes inherited from ProjectFile

#content

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from LicenseFile

#attribution, #gpl?, lesser_gpl_score, #lgpl?, #license, #potential_false_positive?

Methods included from ContentHelper

const_missing, #content_hash, #content_normalized, #content_without_title_and_version, format_percent, #length, #length_delta, #similarity, title_regex, #wordset, wrap

Methods inherited from ProjectFile

#attribution, #confidence, #content_hash, #content_normalized, #copyright?, #directory, #filename, #initialize, #license, #matched_license, #matcher, #path_relative_to_root

Methods included from HashHelper

#to_h

Constructor Details

This class inherits a constructor from Licensee::ProjectFiles::ProjectFile

Class Method Details

.license_content(content) ⇒ Object



43
44
45
46
# File 'lib/licensee/project_files/readme_file.rb', line 43

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

.name_score(filename) ⇒ Object



36
37
38
39
40
41
# File 'lib/licensee/project_files/readme_file.rb', line 36

def self.name_score(filename)
  SCORES.each do |pattern, score|
    return score if pattern&.match?(filename)
  end
  0.0
end

Instance Method Details

#possible_matchersObject



32
33
34
# File 'lib/licensee/project_files/readme_file.rb', line 32

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