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
].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
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/licensee/project_files/project_file.rb', line 34
def initialize(content, metadata = {})
@content = content
@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
|
Instance Attribute Details
#content ⇒ Object
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
#confidence ⇒ Object
Returns the percent confident with the match
58
59
60
|
# File 'lib/licensee/project_files/project_file.rb', line 58
def confidence
matcher && matcher.confidence
end
|
#content_hash ⇒ Object
81
82
83
|
# File 'lib/licensee/project_files/project_file.rb', line 81
def content_hash
nil
end
|
#content_normalized ⇒ Object
85
86
87
|
# File 'lib/licensee/project_files/project_file.rb', line 85
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
#filename ⇒ Object
Also known as:
path
45
46
47
|
# File 'lib/licensee/project_files/project_file.rb', line 45
def filename
@data[:name]
end
|
#license ⇒ Object
Also known as:
match
62
63
64
|
# File 'lib/licensee/project_files/project_file.rb', line 62
def license
matcher && matcher.match
end
|
#matched_license ⇒ Object
69
70
71
|
# File 'lib/licensee/project_files/project_file.rb', line 69
def matched_license
license.spdx_id if license
end
|
#matcher ⇒ Object
53
54
55
|
# File 'lib/licensee/project_files/project_file.rb', line 53
def matcher
@matcher ||= possible_matchers.map { |m| m.new(self) }.find(&:match)
end
|
#possible_matchers ⇒ Object
49
50
51
|
# File 'lib/licensee/project_files/project_file.rb', line 49
def possible_matchers
raise 'Not implemented'
end
|