Class: MaxSizeDetector::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/max_size_detector/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**opts) ⇒ Base

Returns a new instance of Base.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/max_size_detector/base.rb', line 8

def initialize(**opts)
  filename = opts[:filename] || opts[:file]
  @input_file = open(filename)
  @max_size = opts[:max_size].to_i
  @lines = Array.new
  @files = Hash.new
  @output = Hash.new

rescue => error
  print " FAILED!\n#{error}"
end

Instance Attribute Details

#directoriesObject (readonly)

Returns the value of attribute directories.



6
7
8
# File 'lib/max_size_detector/base.rb', line 6

def directories
  @directories
end

#filesObject (readonly)

Returns the value of attribute files.



6
7
8
# File 'lib/max_size_detector/base.rb', line 6

def files
  @files
end

#input_fileObject (readonly)

Returns the value of attribute input_file.



6
7
8
# File 'lib/max_size_detector/base.rb', line 6

def input_file
  @input_file
end

#linesObject (readonly)

Returns the value of attribute lines.



6
7
8
# File 'lib/max_size_detector/base.rb', line 6

def lines
  @lines
end

#outputObject (readonly)

Returns the value of attribute output.



6
7
8
# File 'lib/max_size_detector/base.rb', line 6

def output
  @output
end

Instance Method Details

#extract!Object



20
21
22
23
24
25
# File 'lib/max_size_detector/base.rb', line 20

def extract!
  return unless @input_file

  extract_lines!
  extract_files!
end

#process!Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/max_size_detector/base.rb', line 27

def process!
  return unless @input_file

  files_within_max_size = extract_files_by_max_size
  grouped = group_by(hash_key: :parent_directory, files: files_within_max_size)
  content_to_hash!(grouped)

  @output = extract_files_by_max_size(files: grouped)
  output_within_max_size!
end

#show_outputObject



38
39
40
# File 'lib/max_size_detector/base.rb', line 38

def show_output
  JSON.pretty_generate(JSON.parse(@output.to_json))
end