Class: Logue::Format
- Inherits:
-
Object
- Object
- Logue::Format
- Defined in:
- lib/logue/format.rb
Instance Method Summary collapse
- #print_formatted(file, line, func, msg, lvl, &blk) ⇒ Object
- #trim_left(str, maxlen) ⇒ Object
- #trim_right(str, maxlen) ⇒ Object
Instance Method Details
#print_formatted(file, line, func, msg, lvl, &blk) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/logue/format.rb', line 38 def print_formatted file, line, func, msg, lvl, &blk if trim file = trim_right file, @file_width line = trim_left line, @line_width func = trim_left func, @function_width end hdr = sprintf @format, file, line, func print hdr, msg, lvl, &blk end |
#trim_left(str, maxlen) ⇒ Object
7 8 9 |
# File 'lib/logue/format.rb', line 7 def trim_left str, maxlen str[0 ... maxlen.to_i.abs] end |
#trim_right(str, maxlen) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/logue/format.rb', line 11 def trim_right str, maxlen mxln = maxlen.abs # magic number 3 for the ellipses ... if str.length > mxln path = str.split('/') newstr = "..." path.reverse.each do |element| if newstr.length + element.length > mxln while newstr.length < mxln newstr.insert 0, " " end return newstr else if newstr.length > 3 newstr.insert 3, "/" end newstr.insert 3, element end end newstr else str end end |