Method: Doing::StringHighlight#highlight_tags

Defined in:
lib/doing/string/highlight.rb

#highlight_tags(color = 'yellow', last_color: nil) ⇒ String

Colorize @tags with ANSI escapes

Parameters:

  • color (String) (defaults to: 'yellow')

    color (see #Color)

Returns:

  • (String)

    string with @tags highlighted



18
19
20
21
22
23
24
25
# File 'lib/doing/string/highlight.rb', line 18

def highlight_tags(color = 'yellow', last_color: nil)
  unless last_color
    color = color.split(' ') unless color.is_a?(Array)
    tag_color = color.each_with_object([]) { |c, arr| arr << Doing::Color.send(c) }.join('')
    last_color = last_color_code
  end
  gsub(/(\s|m)(@[^ ("']+)/, "\\1#{tag_color}\\2#{last_color}")
end