Module: HpricotTruncator::NodeWithChildren
- Defined in:
- lib/text-helper.rb
Instance Method Summary collapse
Instance Method Details
#truncate(max_length) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/text-helper.rb', line 17 def truncate(max_length) return self if inner_text.size <= max_length truncated_node = self.dup truncated_node.children = [] each_child do |node| remaining_length = max_length - truncated_node.inner_text.size break if remaining_length == 0 truncated_node.children << node.truncate(remaining_length) end truncated_node end |