我想知道是否有一个插件可以启用一种智能截断。我需要以一个单词或一个句子的精度截断我的文本。
例如:
Post.my_message.smart_truncate(
"Once upon a time in a world far far away. And they found that many people
were sleeping better.", :sentences => 1)
# => Once upon a time in a world far far away.
或者
Post.my_message.smart_truncate(
"Once upon a time in a world far far away. And they found that many people
were sleeping better.", :words => 12)
# => Once upon a time in a world far far away. And they ...