Class: Msf::Ui::Console::TablePrint::HighlightSubstringStyler

Inherits:
Object
  • Object
show all
Defined in:
lib/msf/ui/console/table_print/highlight_substring_styler.rb

Constant Summary collapse

COLOR =
'%bgmag'

Instance Method Summary collapse

Constructor Details

#initialize(substrings) ⇒ HighlightSubstringStyler

Returns a new instance of HighlightSubstringStyler.


10
11
12
# File 'lib/msf/ui/console/table_print/highlight_substring_styler.rb', line 10

def initialize(substrings)
  @substrings = substrings
end

Instance Method Details

#style(value) ⇒ Object


14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/msf/ui/console/table_print/highlight_substring_styler.rb', line 14

def style(value)
  value_cp = value.clone

  @substrings.each do |s|
    # Regex used to pull out matches and preserve case sensitivity
    matches = value_cp.scan(%r{#{Regexp.escape(s)}}i)

    matches.each do |m|
      value_cp.gsub!(m, COLOR + m + '%clr')
    end
  end

  value_cp
end