class LogAnalyzer::PathShortener
Constants
- CHARS_TO_IGNORE
- MAX_LENGTH
Attributes
max[R]
path[R]
Public Class Methods
new(path, max: MAX_LENGTH)
click to toggle source
# File lib/log_analyzer/path_shortener.rb, line 6 def initialize(path, max: MAX_LENGTH) @path = path @max = max end
shrink(path, max: MAX_LENGTH)
click to toggle source
# File lib/log_analyzer/path_shortener.rb, line 11 def self.shrink(path, max: MAX_LENGTH) new(path, max: max).shrink end
Public Instance Methods
shrink()
click to toggle source
# File lib/log_analyzer/path_shortener.rb, line 15 def shrink return path if path.length < max File.join( File.dirname(path).split(File::SEPARATOR).map { |dir| short_name(dir) }, File.basename(path) ) end
Private Instance Methods
short_name(name)
click to toggle source
# File lib/log_analyzer/path_shortener.rb, line 28 def short_name(name) first_char = name[0] || "" # avoid nils in directory names CHARS_TO_IGNORE.include?(first_char) ? name[0..1] : first_char end