Class: DiffChunkBuilder
- Inherits:
-
Object
- Object
- DiffChunkBuilder
- Defined in:
- lib/diff_chunk_builder.rb
Overview
Motiro - A project tracking tool
Copyright (C) 2006-2008 Thiago Arrais
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation; either version 3 of the License, or
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Instance Method Summary collapse
- #get_chunks ⇒ Object
-
#initialize ⇒ DiffChunkBuilder
constructor
A new instance of DiffChunkBuilder.
- #push_addition(text) ⇒ Object
- #push_deletion(text) ⇒ Object
- #push_unchanged(text) ⇒ Object
- #start_line(old_line_num, new_line_num = old_line_num) ⇒ Object
Constructor Details
#initialize ⇒ DiffChunkBuilder
Returns a new instance of DiffChunkBuilder.
19 20 21 22 23 24 |
# File 'lib/diff_chunk_builder.rb', line 19 def initialize @chunks = [] @unmatched_deletions = [] @old_line_num = @new_line_num = 1 needs_new_chunk! end |
Instance Method Details
#get_chunks ⇒ Object
58 59 60 61 |
# File 'lib/diff_chunk_builder.rb', line 58 def get_chunks consume_unmatched_deletions @chunks end |
#push_addition(text) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/diff_chunk_builder.rb', line 46 def push_addition(text) unless @unmatched_deletions.empty? chunk = target_chunk_for(:modification) old_text, old_position = @unmatched_deletions.shift chunk << Line.new(old_text, old_position, text, @new_line_num) else target_chunk_for(:addition) << Line.new(nil, @old_line_num, text, @new_line_num) end @new_line_num += 1 end |
#push_deletion(text) ⇒ Object
33 34 35 36 |
# File 'lib/diff_chunk_builder.rb', line 33 def push_deletion(text) @unmatched_deletions << [text, @old_line_num] @old_line_num += 1 end |
#push_unchanged(text) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/diff_chunk_builder.rb', line 38 def push_unchanged(text) consume_unmatched_deletions target_chunk_for(:unchanged) << Line.new(text, @old_line_num, text, @new_line_num) @old_line_num += 1 @new_line_num += 1 end |
#start_line(old_line_num, new_line_num = old_line_num) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/diff_chunk_builder.rb', line 26 def start_line(old_line_num, new_line_num=old_line_num) consume_unmatched_deletions needs_new_chunk! @chunks << Separator.new(old_line_num - @old_line_num) unless @chunks.empty? @old_line_num, @new_line_num = old_line_num, new_line_num end |