Class: Licensee::ProjectFiles::ProjectFile
- Inherits:
-
Object
- Object
- Licensee::ProjectFiles::ProjectFile
show all
- Extended by:
- Forwardable
- Includes:
- HashHelper
- Defined in:
- lib/licensee/project_files/project_file.rb
Constant Summary
collapse
- HASH_METHODS =
%i[
filename content content_hash content_normalized matcher matched_license
attribution
].freeze
- ENCODING =
Encoding::UTF_8
- ENCODING_OPTIONS =
{
invalid: :replace,
undef: :replace,
replace: ''
}.freeze
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from HashHelper
#to_h
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
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
37
38
39
40
41
42
43
44
45
|
# File 'lib/licensee/project_files/project_file.rb', line 37
def initialize(content, metadata = {})
@content = content.dup
@content.force_encoding(ENCODING)
@content.encode!(ENCODING, **ENCODING_OPTIONS) unless @content.valid_encoding?
@content.encode!(ENCODING, universal_newline: true)
metadata = { name: metadata } if metadata.is_a? String
@data = metadata || {}
end
|
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
13
14
15
|
# File 'lib/licensee/project_files/project_file.rb', line 13
def content
@content
end
|
Instance Method Details
#attribution ⇒ Object
105
106
107
|
# File 'lib/licensee/project_files/project_file.rb', line 105
def attribution
nil
end
|
#confidence ⇒ Object
Returns the percent confident with the match
74
75
76
|
# File 'lib/licensee/project_files/project_file.rb', line 74
def confidence
matcher&.confidence
end
|
#content_hash ⇒ Object
97
98
99
|
# File 'lib/licensee/project_files/project_file.rb', line 97
def content_hash
nil
end
|
#content_normalized ⇒ Object
101
102
103
|
# File 'lib/licensee/project_files/project_file.rb', line 101
def content_normalized
nil
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
#directory ⇒ Object
Also known as:
dir
55
56
57
|
# File 'lib/licensee/project_files/project_file.rb', line 55
def directory
@data[:dir] || '.'
end
|
#filename ⇒ Object
Also known as:
path
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
50
51
52
|
# File 'lib/licensee/project_files/project_file.rb', line 50
def filename
@data[:name]
end
|
#license ⇒ Object
Also known as:
match
78
79
80
|
# File 'lib/licensee/project_files/project_file.rb', line 78
def license
matcher&.match
end
|
#matched_license ⇒ Object
84
85
86
|
# File 'lib/licensee/project_files/project_file.rb', line 84
def matched_license
license&.spdx_id
end
|
#matcher ⇒ Object
69
70
71
|
# File 'lib/licensee/project_files/project_file.rb', line 69
def matcher
@matcher ||= possible_matchers.map { |m| m.new(self) }.find(&:match)
end
|
#path_relative_to_root ⇒ Object
Also known as:
relative_path
60
61
62
|
# File 'lib/licensee/project_files/project_file.rb', line 60
def path_relative_to_root
File.join(directory, filename)
end
|
#possible_matchers ⇒ Object
65
66
67
|
# File 'lib/licensee/project_files/project_file.rb', line 65
def possible_matchers
raise 'Not implemented'
end
|