Skip to content

Instantly share code, notes, and snippets.

@lucianosousa
Created August 25, 2010 15:24
Show Gist options
  • Save lucianosousa/549703 to your computer and use it in GitHub Desktop.
Save lucianosousa/549703 to your computer and use it in GitHub Desktop.
def wtruncate(text, length)
text = text.encode_utf8
if text.length > length
sum = 0
words_ret = []
words = text.split(' ')
words.each do |word|
sum += word.length + 1
break if sum > length
words_ret << word
end
words_ret = words_ret.join(' ')
words_ret << "..."
else
text
end
end
@lucianosousa
Copy link
Author

alterei para o text para text.encode_utf8, para particularidades

@lucianosousa
Copy link
Author

adicionando retirencias

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment