class Blab::Printer
Constants
- DEFAULT_CLASS_NAME_WIDTH
- DEFAULT_CODE_LINES_WIDTH
- DEFAULT_EVENT_WIDTH
- DEFAULT_FILE_LINES_WIDTH
- DEFAULT_METHOD_NAME_WIDTH
- DEFAULT_RU_MAXSS_WIDTH
- DEFAULT_TIME_WIDTH
- PRINT_FIELDS
Attributes
config[R]
logger[R]
Public Class Methods
new(config, logger)
click to toggle source
# File lib/blab/printer.rb, line 22 def initialize(config, logger) @config = config @logger = logger end
Public Instance Methods
code_lines(options= {})
click to toggle source
# File lib/blab/printer.rb, line 50 def code_lines(options= {}) file = options[:file] line = options[:line] width = options[:width] || DEFAULT_CODE_LINES_WIDTH [source_line(file, line).scan(/.{#{width}}|.+/), width] end
file_lines(options = {})
click to toggle source
# File lib/blab/printer.rb, line 43 def file_lines(options = {}) file = options[:file] line = options[:line] width = options[:width] || DEFAULT_FILE_LINES_WIDTH ["#{file}:#{line}".scan(/.{#{width}}|.+/), width] end
files_map()
click to toggle source
# File lib/blab/printer.rb, line 69 def files_map @files_map ||= Hash.new do |h, f| h[f] = File.readlines(f) end end
print(options = {})
click to toggle source
# File lib/blab/printer.rb, line 27 def print(options = {}) strings = config.map do |(type, width)| send(type, options.merge(width: width)) end config_length = config.length final = strings.map { |e| e.first.length }.max.times.map do |i| config_length.times.map do |j| str = strings[j][0][i] || "" # TODO: do not ljust the last element config_length == (j + 1) ? str : str.ljust(strings[j][1]) end.join(" ") end logger.info(final.join("\n")) end
reset_files()
click to toggle source
# File lib/blab/printer.rb, line 65 def reset_files @files_map && @files_map.keys.each { |key| @files_map.delete(key) } end
source_line(file, line)
click to toggle source
TODO: show all relevant file-lines
# File lib/blab/printer.rb, line 76 def source_line(file, line) begin files_map[file][line - 1] rescue "source is unavailable" end end