Class: LicenseFinder::PossibleLicenseFile

Inherits:
Object
  • Object
show all
Defined in:
lib/license_finder/possible_license_file.rb

Instance Method Summary collapse

Constructor Details

#initialize(install_path, file_path) ⇒ PossibleLicenseFile

Returns a new instance of PossibleLicenseFile.



3
4
5
6
# File 'lib/license_finder/possible_license_file.rb', line 3

def initialize(install_path, file_path)
  @install_path = Pathname.new(install_path)
  @file_path = Pathname.new(file_path)
end

Instance Method Details

#file_nameObject



16
17
18
# File 'lib/license_finder/possible_license_file.rb', line 16

def file_name
  @file_path.basename.to_s
end

#file_pathObject



8
9
10
# File 'lib/license_finder/possible_license_file.rb', line 8

def file_path
  @file_path.relative_path_from(@install_path).to_s
end

#full_file_pathObject



12
13
14
# File 'lib/license_finder/possible_license_file.rb', line 12

def full_file_path
  Pathname.new(@file_path).realpath.to_s
end

#licenseObject



24
25
26
27
28
29
30
# File 'lib/license_finder/possible_license_file.rb', line 24

def license
  license = License.all.detect do |klass|
    klass.new(text).matches?
  end

  license.pretty_name if license
end

#textObject



20
21
22
# File 'lib/license_finder/possible_license_file.rb', line 20

def text
  @text ||= @file_path.send(@file_path.respond_to?(:binread) ? :binread : :read)
end