Module: HpricotTruncator::TextNode

Defined in:
lib/truncateHTML/hpricot_truncator.rb

Instance Method Summary collapse

Instance Method Details

#truncate(max_length) ⇒ Object



29
30
31
32
# File 'lib/truncateHTML/hpricot_truncator.rb', line 29

def truncate(max_length)
  # We're using String#scan because Hpricot doesn't distinguish entities.
  Hpricot::Text.new(content.scan(/&#?[^\W_]+;|./).first(max_length).join)
end