Class: ChunkDiffer

Inherits:
Object
  • Object
show all
Defined in:
app/models/revision.rb

Constant Summary collapse

LCS_ACTION_TO_SYMBOL =
{'=' => :unchanged, '!' => :modification,
'-' => :deletion, '+' => :addition}

Instance Method Summary collapse

Instance Method Details

#diff(old_lines, new_lines) ⇒ Object



37
38
39
40
# File 'app/models/revision.rb', line 37

def diff(old_lines, new_lines)
  @chunks = []
  Differ.new(self).diff(old_lines, new_lines)
end

#get_resultObject



56
57
58
# File 'app/models/revision.rb', line 56

def get_result
  @chunks
end

#start_new_chunk(action) ⇒ Object



45
46
47
48
# File 'app/models/revision.rb', line 45

def start_new_chunk(action)
  @chunk = Chunk.new(LCS_ACTION_TO_SYMBOL[action])
  @chunks << @chunk
end

#store_diff(sdiff) ⇒ Object



50
51
52
53
54
# File 'app/models/revision.rb', line 50

def store_diff(sdiff)
  #lcs's position are 0-based, but we want 1-based when rendering
  @chunk << Line.new(sdiff.old_element, sdiff.old_position + 1,
                     sdiff.new_element, sdiff.new_position + 1)
end