Class: Licensee::ProjectFiles::LicenseFile
- Inherits:
-
ProjectFile
- Object
- ProjectFile
- Licensee::ProjectFiles::LicenseFile
- Includes:
- ContentHelper
- Defined in:
- lib/licensee/project_files/license_file.rb
Direct Known Subclasses
Constant Summary collapse
- PREFERRED_EXT =
List of extensions to give preference to
%w[md markdown txt].freeze
- PREFERRED_EXT_REGEX =
/\.#{Regexp.union(PREFERRED_EXT)}\z/- ANY_EXT_REGEX =
Regex to match any extension
%r{\.[^./]+\z}- LICENSE_REGEX =
Regex to match, LICENSE, LICENCE, unlicense, etc.
/(un)?licen[sc]e/i- COPYING_REGEX =
Regex to match COPYING, COPYRIGHT, etc.
/copy(ing|right)/i- OFL_REGEX =
Regex to match OFL.
/ofl/i- FILENAME_REGEXES =
Hash of Regex => score with which to score potential license files
{ /\A#{LICENSE_REGEX}\z/ => 1.0, # LICENSE /\A#{LICENSE_REGEX}#{PREFERRED_EXT_REGEX}\z/ => 0.9, # LICENSE.md /\A#{COPYING_REGEX}\z/ => 0.8, # COPYING /\A#{COPYING_REGEX}#{PREFERRED_EXT_REGEX}\z/ => 0.7, # COPYING.md /\A#{LICENSE_REGEX}#{ANY_EXT_REGEX}\z/ => 0.6, # LICENSE.textile /\A#{COPYING_REGEX}#{ANY_EXT_REGEX}\z/ => 0.5, # COPYING.textile /#{LICENSE_REGEX}-/ => 0.4, # LICENSE-MIT /#{COPYING_REGEX}-/ => 0.35, # COPYING-MIT /-#{LICENSE_REGEX}/ => 0.3, # MIT-LICENSE-MIT /-#{COPYING_REGEX}/ => 0.25, # MIT-COPYING /\A#{OFL_REGEX}#{PREFERRED_EXT_REGEX}/ => 0.2, # OFL.md /\A#{OFL_REGEX}#{ANY_EXT_REGEX}/ => 0.1, # OFL.textile /\A#{OFL_REGEX}\z/ => 0.05, # OFL // => 0.0 # Catch all }.freeze
- CC_FALSE_POSITIVE_REGEX =
CC-NC and CC-ND are not open source licenses and should not be detected as CC-BY or CC-BY-SA which are 98%+ similar
/ ^(creative\ commons\ )?Attribution-(NonCommercial|NoDerivatives) /xi
Constants included from ContentHelper
ContentHelper::ALT_TITLE_REGEX, ContentHelper::DIGEST, ContentHelper::END_OF_TERMS_REGEX, ContentHelper::HR_REGEX
Constants inherited from ProjectFile
ProjectFile::ENCODING, ProjectFile::ENCODING_OPTIONS
Instance Attribute Summary
Attributes inherited from ProjectFile
Class Method Summary collapse
-
.lesser_gpl_score(filename) ⇒ Object
case-insensitive block to determine if the given file is LICENSE.lesser.
- .name_score(filename) ⇒ Object
Instance Method Summary collapse
- #attribution ⇒ Object
- #gpl? ⇒ Boolean
- #lgpl? ⇒ Boolean
- #license ⇒ Object
- #possible_matchers ⇒ Object
-
#potential_false_positive? ⇒ Boolean
Is this file likely to result in a creative commons false positive?.
Methods included from ContentHelper
#content_hash, #content_normalized, #content_without_title_and_version, format_percent, #length, #length_delta, #max_delta, #similarity, #wordset, wrap
Methods inherited from ProjectFile
#confidence, #filename, #initialize, #matcher
Constructor Details
This class inherits a constructor from Licensee::ProjectFiles::ProjectFile
Class Method Details
.lesser_gpl_score(filename) ⇒ Object
case-insensitive block to determine if the given file is LICENSE.lesser
84 85 86 |
# File 'lib/licensee/project_files/license_file.rb', line 84 def self.lesser_gpl_score(filename) filename.casecmp('copying.lesser').zero? ? 1 : 0 end |
.name_score(filename) ⇒ Object
79 80 81 |
# File 'lib/licensee/project_files/license_file.rb', line 79 def self.name_score(filename) FILENAME_REGEXES.find { |regex, _| filename =~ regex }[1] end |
Instance Method Details
#attribution ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/licensee/project_files/license_file.rb', line 50 def attribution @attribution ||= begin matches = Matchers::Copyright::REGEX .match(content_without_title_and_version) matches[0] if matches end end |
#gpl? ⇒ Boolean
67 68 69 |
# File 'lib/licensee/project_files/license_file.rb', line 67 def gpl? license && license.gpl? end |
#lgpl? ⇒ Boolean
63 64 65 |
# File 'lib/licensee/project_files/license_file.rb', line 63 def lgpl? LicenseFile.lesser_gpl_score(filename) == 1 && license && license.lgpl? end |
#license ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/licensee/project_files/license_file.rb', line 71 def license if matcher && matcher.match matcher.match else License.find('other') end end |
#possible_matchers ⇒ Object
46 47 48 |
# File 'lib/licensee/project_files/license_file.rb', line 46 def possible_matchers [Matchers::Copyright, Matchers::Exact, Matchers::Dice] end |
#potential_false_positive? ⇒ Boolean
Is this file likely to result in a creative commons false positive?
59 60 61 |
# File 'lib/licensee/project_files/license_file.rb', line 59 def potential_false_positive? content.strip =~ CC_FALSE_POSITIVE_REGEX end |