Class: Renamr::TruncateAction
Overview
Limits file length.
Instance Method Summary collapse
- #do(src) ⇒ Object
-
#initialize(lim) ⇒ TruncateAction
constructor
A new instance of TruncateAction.
Methods inherited from Action
Constructor Details
#initialize(lim) ⇒ TruncateAction
Returns a new instance of TruncateAction.
11 12 13 14 15 |
# File 'lib/renamr/truncate.rb', line 11 def initialize(lim) raise 'lim cannot be nil.' if lim.nil? @lim = lim end |
Instance Method Details
#do(src) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/renamr/truncate.rb', line 17 def do(src) return src unless src.length > @lim ext = File.extname(src) len = ext.length dst = len >= @lim ? ext[0..@lim - 1] : src[0..@lim - 1 - len] << ext dst.gsub!(/-$/, '') dst.gsub!('-.', '.') dst end |