lib/licensee/project_files/readme_file.rb in licensee-9.7.0 vs lib/licensee/project_files/readme_file.rb in licensee-9.8.0
- old
+ new
@@ -1,22 +1,31 @@
module Licensee
module ProjectFiles
class ReadmeFile < Licensee::ProjectFiles::LicenseFile
+ EXTENSIONS = %w[md markdown mdown txt rdoc].freeze
SCORES = {
- /\AREADME\z/i => 1.0,
- /\AREADME\.(md|markdown|mdown|txt)\z/i => 0.9
+ /\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 = /^
- (?:\#+\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
+ (?: # 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