class Skygrepe::Formatter

Public Class Methods

new(keyword, config) click to toggle source
# File lib/skygrepe.rb, line 102
def initialize(keyword, config)
  @keyword = keyword
  @time_format = config["time_format"] || "%Y-%m-%d %H:%M"
end

Public Instance Methods

detail(row) click to toggle source
# File lib/skygrepe.rb, line 113
def detail(row)
  row[1] = Time.at(row[1]).strftime(@time_format)
  row[4] = format_message(row[4] || '')
  row
end
format_message(msg) click to toggle source
# File lib/skygrepe.rb, line 119
def format_message(msg)
  CGI.unescape_html(msg || '').gsub(/(#{Regexp.escape(@keyword)})/i){ "\e[32m#{$1}\e[0m" }
end
list(row) click to toggle source
# File lib/skygrepe.rb, line 107
def list(row)
  row[1] = Time.at(row[1]).strftime(@time_format)
  row[4] = format_message(row[4] || '').gsub(/[\n\r]/m, '')
  row
end