Class: Skygrepe::Formatter
- Inherits:
-
Object
- Object
- Skygrepe::Formatter
- Defined in:
- lib/skygrepe.rb
Instance Method Summary collapse
- #detail(row) ⇒ Object
- #format_message(msg) ⇒ Object
-
#initialize(keyword, config) ⇒ Formatter
constructor
A new instance of Formatter.
- #list(row) ⇒ Object
Constructor Details
#initialize(keyword, config) ⇒ Formatter
Returns a new instance of Formatter.
102 103 104 105 |
# File 'lib/skygrepe.rb', line 102 def initialize(keyword, config) @keyword = keyword @time_format = config["time_format"] || "%Y-%m-%d %H:%M" end |
Instance Method Details
#detail(row) ⇒ Object
113 114 115 116 117 |
# File 'lib/skygrepe.rb', line 113 def detail(row) row[1] = Time.at(row[1]).strftime(@time_format) row[4] = (row[4] || '') row end |
#format_message(msg) ⇒ Object
119 120 121 |
# File 'lib/skygrepe.rb', line 119 def (msg) CGI.unescape_html(msg || '').gsub(/(#{Regexp.escape(@keyword)})/i){ "\e[32m#{$1}\e[0m" } end |
#list(row) ⇒ Object
107 108 109 110 111 |
# File 'lib/skygrepe.rb', line 107 def list(row) row[1] = Time.at(row[1]).strftime(@time_format) row[4] = (row[4] || '').gsub(/[\n\r]/m, '') row end |