Class: Nokogiri::XML::Text
- Inherits:
-
Object
- Object
- Nokogiri::XML::Text
- Defined in:
- lib/html_truncator.rb
Instance Method Summary collapse
Instance Method Details
#truncate(max, opts) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/html_truncator.rb', line 64 def truncate(max, opts) if opts[:length_in_chars] count = content.length return [to_xhtml, count, opts] if count <= max && max > 0 [content.slice(0, max), count, opts] else words = content.split count = words.length return [to_xhtml, count, opts] if count <= max && max > 0 [words.slice(0, max).join(' '), count, opts] end end |