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 37
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 106
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 75
def confidence
  matcher&.confidence
end
content_hash() click to toggle source
# File lib/licensee/project_files/project_file.rb, line 98
def content_hash
  nil
end
content_normalized() click to toggle source
# File lib/licensee/project_files/project_file.rb, line 102
def content_normalized
  nil
end
dir()
Alias for: directory
directory() click to toggle source
# File lib/licensee/project_files/project_file.rb, line 56
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 51
def filename
  @data[:name]
end
Also aliased as: path
license() click to toggle source
# File lib/licensee/project_files/project_file.rb, line 79
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 85
def matched_license
  license&.spdx_id
end
matcher() click to toggle source
# File lib/licensee/project_files/project_file.rb, line 70
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 61
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 66
def possible_matchers
  raise 'Not implemented'
end
relative_path()