Class: Licensee::ProjectFiles::ProjectFile

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/licensee/project_files/project_file.rb

Direct Known Subclasses

LicenseFile, PackageManagerFile

Constant Summary collapse

ENCODING =
Encoding::UTF_8
ENCODING_OPTIONS =
{
  invalid: :replace,
  undef:   :replace,
  replace: ''
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content, metadata = {}) ⇒ ProjectFile

Create a new Licensee::ProjectFile with content and metadata

content - file content metadata - can be either the string filename, or a hash containing

 about the file content. If a hash is given, the
filename should be given using the :name key. See individual
project types for additional available 

Returns a new Licensee::ProjectFile



29
30
31
32
33
34
35
36
37
38
# File 'lib/licensee/project_files/project_file.rb', line 29

def initialize(content,  = {})
  @content = content
  @content.force_encoding(ENCODING)
  unless @content.valid_encoding?
    @content.encode!(ENCODING, ENCODING_OPTIONS)
  end

   = { name:  } if .is_a? String
  @data =  || {}
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



11
12
13
# File 'lib/licensee/project_files/project_file.rb', line 11

def content
  @content
end

Instance Method Details

#confidenceObject

Returns the percent confident with the match



53
54
55
# File 'lib/licensee/project_files/project_file.rb', line 53

def confidence
  matcher && matcher.confidence
end

#copyright?Boolean

Is this file a COPYRIGHT file with only a copyright statement? If so, it can be excluded from determining if a project has >1 license

Returns:

  • (Boolean)


66
67
68
69
70
# File 'lib/licensee/project_files/project_file.rb', line 66

def copyright?
  return false unless is_a?(LicenseFile)
  return false unless matcher.is_a?(Matchers::Copyright)
  filename =~ /\Acopyright(?:#{LicenseFile::OTHER_EXT_REGEX})?\z/i
end

#filenameObject Also known as: path



40
41
42
# File 'lib/licensee/project_files/project_file.rb', line 40

def filename
  @data[:name]
end

#licenseObject Also known as: match



57
58
59
# File 'lib/licensee/project_files/project_file.rb', line 57

def license
  matcher && matcher.match
end

#matcherObject



48
49
50
# File 'lib/licensee/project_files/project_file.rb', line 48

def matcher
  @matcher ||= possible_matchers.map { |m| m.new(self) }.find(&:match)
end

#possible_matchersObject



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

def possible_matchers
  raise 'Not implemented'
end