Module: NokogiriTruncator::TextNode
- Defined in:
- lib/bergamasco/summarize.rb
Instance Method Summary collapse
Instance Method Details
#truncate(max_length, ellipsis) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/bergamasco/summarize.rb', line 62 def truncate(max_length, ellipsis) # Don't break in the middle of a word trimmed_content = content.match(/(.{1,#{max_length}}[\w]*)/m).to_s trimmed_content << ellipsis if trimmed_content.length < content.length Nokogiri::XML::Text.new(trimmed_content, parent) end |