Module: Logue::PathUtil
Instance Method Summary collapse
- #trim_left(str, maxlen) ⇒ Object
- #trim_path_right(path, maxlen) ⇒ Object
- #trim_right(str, maxlen) ⇒ Object
Instance Method Details
#trim_left(str, maxlen) ⇒ Object
5 6 7 |
# File 'lib/logue/format/pathutil.rb', line 5 def trim_left str, maxlen str[0, maxlen] || "" end |
#trim_path_right(path, maxlen) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/logue/format/pathutil.rb', line 17 def trim_path_right path, maxlen return "" if maxlen < 0 comps = path.split "/" str = comps.pop comps.reverse.each do |comp| newstr = comp + "/" + str if newstr.length + 4 <= maxlen str = newstr else newstr = ".../" + str if newstr.length <= maxlen str = newstr end break end end str end |
#trim_right(str, maxlen) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/logue/format/pathutil.rb', line 9 def trim_right str, maxlen if str.length > maxlen trim_path_right str, maxlen else str end end |