Class: MaxSizeDetector::Base
- Inherits:
-
Object
- Object
- MaxSizeDetector::Base
- Defined in:
- lib/max_size_detector/base.rb
Instance Attribute Summary collapse
-
#directories ⇒ Object
readonly
Returns the value of attribute directories.
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#input_file ⇒ Object
readonly
Returns the value of attribute input_file.
-
#lines ⇒ Object
readonly
Returns the value of attribute lines.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
Instance Method Summary collapse
- #extract! ⇒ Object
-
#initialize(**opts) ⇒ Base
constructor
A new instance of Base.
- #process! ⇒ Object
- #show_output ⇒ Object
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
#directories ⇒ Object (readonly)
Returns the value of attribute directories.
6 7 8 |
# File 'lib/max_size_detector/base.rb', line 6 def directories @directories end |
#files ⇒ Object (readonly)
Returns the value of attribute files.
6 7 8 |
# File 'lib/max_size_detector/base.rb', line 6 def files @files end |
#input_file ⇒ Object (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 |
#lines ⇒ Object (readonly)
Returns the value of attribute lines.
6 7 8 |
# File 'lib/max_size_detector/base.rb', line 6 def lines @lines end |
#output ⇒ Object (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_output ⇒ Object
38 39 40 |
# File 'lib/max_size_detector/base.rb', line 38 def show_output JSON.pretty_generate(JSON.parse(@output.to_json)) end |