class Licensee::ProjectFiles::ProjectFile

Constants

ENCODING
ENCODING_OPTIONS
HASH_METHODS

Attributes

content[R]

Public Class Methods

new(content, metadata = {}) click to toggle source

Create a new Licensee::ProjectFile with content and metadata

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

metadata 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 metadata

Returns a new Licensee::ProjectFile

# File lib/licensee/project_files/project_file.rb, line 36
def initialize(content, metadata = {})
  @content = content.dup
  @content.force_encoding(ENCODING)
  unless @content.valid_encoding?
    @content.encode!(ENCODING, **ENCODING_OPTIONS)
  end

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

Public Instance Methods

attribution() click to toggle source
# File lib/licensee/project_files/project_file.rb, line 105
def attribution
  nil
end
confidence() click to toggle source

Returns the percent confident with the match

# File lib/licensee/project_files/project_file.rb, line 74
def confidence
  matcher&.confidence
end
content_hash() click to toggle source
# File lib/licensee/project_files/project_file.rb, line 97
def content_hash
  nil
end
content_normalized() click to toggle source
# File lib/licensee/project_files/project_file.rb, line 101
def content_normalized
  nil
end
dir()
Alias for: directory
directory() click to toggle source
# File lib/licensee/project_files/project_file.rb, line 55
def directory
  @data[:dir] || '.'
end
Also aliased as: dir
filename() click to toggle source

TODO: In the next major release, filename should be the basename and path should be either the absolute path or the relative path to the project root, but maintaining the alias for backward compatability

# File lib/licensee/project_files/project_file.rb, line 50
def filename
  @data[:name]
end
Also aliased as: path
license() click to toggle source
# File lib/licensee/project_files/project_file.rb, line 78
def license
  matcher&.match
end
Also aliased as: match
match()
Alias for: license
matched_license() click to toggle source
# File lib/licensee/project_files/project_file.rb, line 84
def matched_license
  license&.spdx_id
end
matcher() click to toggle source
# File lib/licensee/project_files/project_file.rb, line 69
def matcher
  @matcher ||= possible_matchers.map { |m| m.new(self) }.find(&:match)
end
path()
Alias for: filename
path_relative_to_root() click to toggle source
# File lib/licensee/project_files/project_file.rb, line 60
def path_relative_to_root
  File.join(directory, filename)
end
Also aliased as: relative_path
possible_matchers() click to toggle source
# File lib/licensee/project_files/project_file.rb, line 65
def possible_matchers
  raise 'Not implemented'
end
relative_path()