Class: BigFiles::Inspector

Inherits:
Object
  • Object
show all
Defined in:
lib/bigfiles/inspector.rb

Overview

Investigate a project and generate a report on the n biggest files

Instance Method Summary collapse

Constructor Details

#initialize(config: Config.new, source_file_globber: SourceFinder::SourceFileGlobber.new, file_with_lines: FileWithLines, io: Kernel) ⇒ Inspector

Returns a new instance of Inspector.



10
11
12
13
14
15
16
17
18
# File 'lib/bigfiles/inspector.rb', line 10

def initialize(config: Config.new,
               source_file_globber: SourceFinder::SourceFileGlobber.new,
               file_with_lines: FileWithLines,
               io: Kernel)
  @config = config
  @source_file_globber = source_file_globber
  @file_with_lines = file_with_lines
  @io = io
end

Instance Method Details

#find_analyze_and_report_on_filesObject



29
30
31
32
33
# File 'lib/bigfiles/inspector.rb', line 29

def find_analyze_and_report_on_files
  find_and_analyze.each do |file|
    @io.puts "#{file.num_lines}: #{file.filename}"
  end
end

#find_and_analyzeObject



20
21
22
23
24
25
26
27
# File 'lib/bigfiles/inspector.rb', line 20

def find_and_analyze
  @source_file_globber.source_files_glob = @config.glob
  @source_file_globber.source_files_exclude_glob = @config.exclude
  file_list = @source_file_globber.source_files_arr
  file_list.map do |filename|
    @file_with_lines.new(filename)
  end.sort.reverse[0..(@config.num_files - 1)]
end