11: def initialize(str)
12: status = STATUS_BOTH
13:
14: section = 1
15: @conflicts = 0
16: @text = {}
17:
18: lines = str.split("\n")
19: lines.each do |line|
20: if /^<<<<<<< (.*?)/.match(line)
21: status = STATUS_OURS
22: @conflicts += 1
23: section += 1
24: elsif line == '======='
25: status = STATUS_THEIRS
26: elsif /^>>>>>>> (.*?)/.match(line)
27: status = STATUS_BOTH
28: section += 1
29: else
30: @text[section] ||= {}
31: @text[section][status] ||= []
32: @text[section][status] << line
33: end
34: end
35: @text = @text.values
36: @sections = @text.size
37: end