Module: HpricotTruncator::TextNode

Defined in:
lib/hpricot-util.rb

Instance Method Summary collapse

Instance Method Details

#truncate(num_words, truncate_string) ⇒ Object



64
65
66
67
68
69
# File 'lib/hpricot-util.rb', line 64

def truncate(num_words, truncate_string)
  words = content.split
  self.content = (words.size <= num_words ?
    content : words[0..num_words-1].join(' ') + truncate_string).to_s
  self
end