Class: LicenseFinder::PossibleLicenseFile

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

Instance Method Summary collapse

Constructor Details

#initialize(path, options = {}) ⇒ PossibleLicenseFile

Returns a new instance of PossibleLicenseFile.



5
6
7
8
9
10
11
12
# File 'lib/license_finder/package_utils/possible_license_file.rb', line 5

def initialize(path, options = {})
  if !path.is_a?(Zip::Entry)
    @path = Pathname(path)
  else
    @zip_entry = path
  end
  @logger = options[:logger]
end

Instance Method Details

#licenseObject



18
19
20
# File 'lib/license_finder/package_utils/possible_license_file.rb', line 18

def license
  License.find_by_text(text)
end

#pathObject



14
15
16
# File 'lib/license_finder/package_utils/possible_license_file.rb', line 14

def path
  @path.to_s
end

#textObject



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

def text
  if @zip_entry
    @zip_entry.get_input_stream.read
  elsif @path.exist?
    @text ||= (@path.respond_to?(:binread) ? @path.binread : @path.read)
  else
    @logger.info('ERROR', "#{@path} does not exists", color: :red)
    ''
  end
end