38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/ree_lib/packages/ree_string/package/ree_string/functions/truncate.rb', line 38
def call(str, truncate_at, **opts)
return str.dup unless str.length > truncate_at
omission = opts[:omission] || DEFAULT_OMISSION
length_with_room_for_omission = truncate_at - omission.length
stop = if opts[:separator]
str.rindex(opts[:separator], length_with_room_for_omission) || length_with_room_for_omission
else
length_with_room_for_omission
end
+"#{str[0, stop]}#{omission}"
end
|