Module: HpricotTruncator::NodeWithChildren
- Defined in:
- app/helpers/text_helper.rb
Instance Method Summary collapse
Instance Method Details
#truncate(length) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/helpers/text_helper.rb', line 24 def truncate(length) return self if inner_text.chars.count <= length truncated_node = self.dup truncated_node.children = [] each_child do |node| remaining_length = length - truncated_node.inner_text.chars.count break if remaining_length == 0 truncated_node.children << node.truncate(remaining_length) end truncated_node end |