Class: Gitlab::WordDiff::ChunkCollection
- Inherits:
-
Object
- Object
- Gitlab::WordDiff::ChunkCollection
- Defined in:
- lib/gitlab/word_diff/chunk_collection.rb
Instance Method Summary collapse
- #add(chunk) ⇒ Object
- #content ⇒ Object
-
#initialize ⇒ ChunkCollection
constructor
A new instance of ChunkCollection.
- #marker_ranges ⇒ Object
- #reset ⇒ Object
Constructor Details
#initialize ⇒ ChunkCollection
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 |
#content ⇒ Object
14 15 16 |
# File 'lib/gitlab/word_diff/chunk_collection.rb', line 14 def content @chunks.join('') end |
#marker_ranges ⇒ Object
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 |
#reset ⇒ Object
18 19 20 |
# File 'lib/gitlab/word_diff/chunk_collection.rb', line 18 def reset @chunks = [] end |