Class: WarningHandler

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/log_parser/warning_handler.rb

Overview

Handles warnings found when reading logs

Constant Summary

Constants included from Constants

Constants::DEFAULT_LOG, Constants::DEFAULT_OPTIONS, Constants::DESCRIPTORS, Constants::INFO_TITLES, Constants::LOG_WARNINGS, Constants::OPTION_DESCRIPTIONS, Constants::OUTPUT_COLORS, Constants::VALIDATION_NAMES, Constants::VALID_ADDRESS, Constants::VALID_IP4, Constants::VALID_IP6, Constants::VALID_LOG, Constants::VALID_PATH, Constants::WARNINGS_JSON, Constants::WARNING_COLORS

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(warnings: []) ⇒ WarningHandler

Returns a new instance of WarningHandler.



9
10
11
# File 'lib/log_parser/warning_handler.rb', line 9

def initialize(warnings: [])
  @warnings = warnings
end

Instance Attribute Details

#warning_infoObject (readonly)

Returns the value of attribute warning_info.



7
8
9
# File 'lib/log_parser/warning_handler.rb', line 7

def warning_info
  @warning_info
end

#warningsObject (readonly)

Returns the value of attribute warnings.



7
8
9
# File 'lib/log_parser/warning_handler.rb', line 7

def warnings
  @warnings
end

Instance Method Details

#store_warning_info(warning_info: {}) ⇒ Object



13
14
15
16
# File 'lib/log_parser/warning_handler.rb', line 13

def store_warning_info(warning_info: {})
  @warning_info = warning_info
  self
end

#warnings_summaryObject



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/log_parser/warning_handler.rb', line 18

def warnings_summary
  summary = {}
  warning_info.each do |type, info|
    summary[type] = {}
    summary[type][:name] = info[:name]
    summary[type][:important] = info[:important]
    summary[type][:warnings] = @warnings
                               .filter { |warning| warning[:type] == type }
                               .map { |warning| warning[:message] }
  end
  summary
end