Class: Licensee::ProjectFiles::ProjectFile
- Inherits:
-
Object
- Object
- Licensee::ProjectFiles::ProjectFile
- Extended by:
- Forwardable
- Defined in:
- lib/licensee/project_files/project_file.rb
Direct Known Subclasses
Constant Summary collapse
- ENCODING =
Encoding::UTF_8
- ENCODING_OPTIONS =
{ invalid: :replace, undef: :replace, replace: '' }.freeze
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
Instance Method Summary collapse
-
#confidence ⇒ Object
Returns the percent confident with the match.
-
#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: #path)
-
#initialize(content, metadata = {}) ⇒ ProjectFile
constructor
Create a new Licensee::ProjectFile with content and metadata.
- #license ⇒ Object (also: #match)
- #matcher ⇒ Object
- #possible_matchers ⇒ Object
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
#content ⇒ Object (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
#confidence ⇒ Object
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
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 |
#filename ⇒ Object Also known as: path
40 41 42 |
# File 'lib/licensee/project_files/project_file.rb', line 40 def filename @data[:name] end |
#license ⇒ Object Also known as: match
57 58 59 |
# File 'lib/licensee/project_files/project_file.rb', line 57 def license matcher && matcher.match end |
#matcher ⇒ Object
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_matchers ⇒ Object
44 45 46 |
# File 'lib/licensee/project_files/project_file.rb', line 44 def possible_matchers raise 'Not implemented' end |