Class: Gitlab::WordDiff::ChunkCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/word_diff/chunk_collection.rb

Instance Method Summary collapse

Constructor Details

#initializeChunkCollection

Returns a new instance of ChunkCollection.


6
7
8
# File 'lib/gitlab/word_diff/chunk_collection.rb', line 6

def initialize
  @chunks = []
end

Instance Method Details

#add(chunk) ⇒ Object


10
11
12
# File 'lib/gitlab/word_diff/chunk_collection.rb', line 10

def add(chunk)
  @chunks << chunk
end

#contentObject


14
15
16
# File 'lib/gitlab/word_diff/chunk_collection.rb', line 14

def content
  @chunks.join('')
end

#marker_rangesObject


22
23
24
25
26
27
28
29
30
31
32
# File 'lib/gitlab/word_diff/chunk_collection.rb', line 22

def marker_ranges
  start = 0

  @chunks.each_with_object([]) do |element, ranges|
    mode = mode_for_element(element)

    ranges << Gitlab::MarkerRange.new(start, start + element.length - 1, mode: mode) if mode

    start += element.length
  end
end

#resetObject


18
19
20
# File 'lib/gitlab/word_diff/chunk_collection.rb', line 18

def reset
  @chunks = []
end