Class: Crm::ArticleRevisionDiffRowComponent::SegmentCursor
- Inherits:
-
Object
- Object
- Crm::ArticleRevisionDiffRowComponent::SegmentCursor
- Defined in:
- app/components/crm/article_revision_diff_row_component/segment_cursor.rb
Overview
Consumes diff segments across multiple DOM text nodes without flattening
the surrounding headings, lists, tables, and links.
Instance Method Summary collapse
-
#initialize(segments) ⇒ SegmentCursor
constructor
A new instance of SegmentCursor.
-
#take(text) ⇒ Array<Array(String, Boolean)>
Splits the given text into pieces aligned with the remaining segments.
Constructor Details
#initialize(segments) ⇒ SegmentCursor
Returns a new instance of SegmentCursor.
7 8 9 10 11 |
# File 'app/components/crm/article_revision_diff_row_component/segment_cursor.rb', line 7 def initialize(segments) @segments = segments @segment_index = 0 @segment_offset = 0 end |
Instance Method Details
#take(text) ⇒ Array<Array(String, Boolean)>
Splits the given text into pieces aligned with the remaining segments.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/components/crm/article_revision_diff_row_component/segment_cursor.rb', line 17 def take(text) remaining = text.dup pieces = [] while remaining.length.positive? segment = current_segment unless segment pieces << [remaining, false] break end length = [remaining.length, available_length].min pieces << [remaining.slice!(0, length), segment.last] consume(length) end pieces end |