Skip to content

Instantly share code, notes, and snippets.

@etjossem
Created January 28, 2013 16:34
Show Gist options
  • Save etjossem/4657023 to your computer and use it in GitHub Desktop.
Save etjossem/4657023 to your computer and use it in GitHub Desktop.
def confined_truncation(text, maxCharsPerWord = 20, maxCharsTotal = 80)
text = text.to_s.split(' ')
text = text.collect {|word| truncate(word, :length => maxCharsPerWord - 3, :omission => '...')}.join(" ")
return truncate(text, :separator => " " , :length => maxCharsTotal - 3, :omission => '...')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment