Class: LogAnalyzer::Utils

Inherits:
Object
  • Object
show all
Defined in:
lib/log_analyzer/utils.rb

Constant Summary collapse

DANGER_DEFAULT =

ms

800
WARNING_DEFAULT =

ms

400
INFO_DEFAULT =

ms

100
DEFAULT_PATH_WIDTH =
60
PARTIAL_LABEL =
" P ".on_green.black.freeze
VIEW_LABEL =
" V ".on_yellow.black.freeze

Class Method Summary collapse

Class Method Details

.avg_label(avg) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/log_analyzer/utils.rb', line 26

def Utils.avg_label(avg)
  str = avg.to_s
  if avg > DANGER_DEFAULT
    str.white.on_red
  elsif avg > WARNING_DEFAULT
    str.red
  elsif avg > INFO_DEFAULT
    str.yellow
  else
    str.green
  end
end

.find_type(view) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/log_analyzer/utils.rb', line 10

def Utils.find_type(view)
  if view.split('/'.freeze).last[0] == '_'.freeze
    LogAnalyzer::Configuration::PARTIALS
  else
    LogAnalyzer::Configuration::VIEWS
  end
end

.path_to_display(path, short: false, length: DEFAULT_PATH_WIDTH) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/log_analyzer/utils.rb', line 39

def Utils.path_to_display(path, short: false, length: DEFAULT_PATH_WIDTH)
  if short
    PathShortener.shrink(path, max: length.last)
  else
    path[length]
  end
end

.report_name(extension) ⇒ Object



47
48
49
# File 'lib/log_analyzer/utils.rb', line 47

def Utils.report_name(extension)
  "report-log-analyzer-#{Time.now.strftime('%Y-%m-%d_%H-%M-%S')}.#{extension}"
end

.type_label(type) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/log_analyzer/utils.rb', line 18

def Utils.type_label(type)
  if type == LogAnalyzer::Configuration::PARTIALS
    PARTIAL_LABEL
  else
    VIEW_LABEL
  end
end