Class: Licensee::Project::File

Inherits:
Object
  • Object
show all
Defined in:
lib/licensee/project_file.rb

Direct Known Subclasses

LicenseFile, PackageInfo

Constant Summary collapse

ENCODING =
Encoding::UTF_8
ENCODING_OPTIONS =
{
  invalid: :replace,
  undef:   :replace,
  replace: ''
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content, filename = nil) ⇒ File

Returns a new instance of File.



13
14
15
16
17
# File 'lib/licensee/project_file.rb', line 13

def initialize(content, filename = nil)
  @content = content
  @content.encode!(ENCODING, ENCODING_OPTIONS)
  @filename = filename
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



4
5
6
# File 'lib/licensee/project_file.rb', line 4

def content
  @content
end

#filenameObject (readonly) Also known as: path

Returns the value of attribute filename.



4
5
6
# File 'lib/licensee/project_file.rb', line 4

def filename
  @filename
end

Instance Method Details

#confidenceObject

Returns the percent confident with the match



24
25
26
# File 'lib/licensee/project_file.rb', line 24

def confidence
  matcher && matcher.confidence
end

#licenseObject Also known as: match



28
29
30
# File 'lib/licensee/project_file.rb', line 28

def license
  matcher && matcher.match
end

#matcherObject



19
20
21
# File 'lib/licensee/project_file.rb', line 19

def matcher
  @matcher ||= possible_matchers.map { |m| m.new(self) }.find(&:match)
end