Class: LogAnalyzer::PathShortener
- Inherits:
-
Object
- Object
- LogAnalyzer::PathShortener
- Defined in:
- lib/log_analyzer/path_shortener.rb
Constant Summary collapse
- CHARS_TO_IGNORE =
%w(.)
- MAX_LENGTH =
80
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(path, max: MAX_LENGTH) ⇒ PathShortener
constructor
A new instance of PathShortener.
- #shrink ⇒ Object
Constructor Details
#initialize(path, max: MAX_LENGTH) ⇒ PathShortener
Returns a new instance of PathShortener.
6 7 8 9 |
# File 'lib/log_analyzer/path_shortener.rb', line 6 def initialize(path, max: MAX_LENGTH) @path = path @max = max end |
Class Method Details
.shrink(path, max: MAX_LENGTH) ⇒ Object
11 12 13 |
# File 'lib/log_analyzer/path_shortener.rb', line 11 def self.shrink(path, max: MAX_LENGTH) new(path, max: max).shrink end |
Instance Method Details
#shrink ⇒ Object
15 16 17 18 19 20 21 22 |
# 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 |