module Truncator::ExtendedString
Public Instance Methods
invalid_length?(*args)
click to toggle source
# File lib/truncator/extended_string.rb, line 27 def invalid_length?(*args) not valid_length?(*args) end
truncate(*args)
click to toggle source
# File lib/truncator/extended_string.rb, line 19 def truncate(*args) self.dup.truncate!(*args) end
truncate!(length, separator = nil)
click to toggle source
# File lib/truncator/extended_string.rb, line 10 def truncate!(length, separator = nil) separator ||= self.separator fail ArgumentError, 'Separator should be present. Pass it via last argument or set globally String.separator=' unless separator if self.length > length self[(length - separator.length)..-1] = separator end self end
valid_length?(valid_length)
click to toggle source
# File lib/truncator/extended_string.rb, line 23 def valid_length?(valid_length) self.length <= valid_length end