Class: Grit::Merge

Inherits:
Object
  • Object
show all
Defined in:
lib/grit/merge.rb

Constant Summary collapse

STATUS_BOTH =
'both'
STATUS_OURS =
'ours'
STATUS_THEIRS =
'theirs'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str) ⇒ Merge

Returns a new instance of Merge.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/grit/merge.rb', line 11

def initialize(str)
  status = STATUS_BOTH

  section = 1
  @conflicts = 0
  @text = {}

  lines = str.split("\n")
  lines.each do |line|
    if /^<<<<<<< (.*?)/.match(line)
      status = STATUS_OURS
      @conflicts += 1
      section += 1
    elsif line == '======='
      status = STATUS_THEIRS
    elsif /^>>>>>>> (.*?)/.match(line)
      status = STATUS_BOTH
      section += 1
    else
      @text[section] ||= {}
      @text[section][status] ||= []
      @text[section][status] << line
    end
  end
  @text = @text.values
  @sections = @text.size
end

Instance Attribute Details

#conflictsObject (readonly)

Returns the value of attribute conflicts.



9
10
11
# File 'lib/grit/merge.rb', line 9

def conflicts
  @conflicts
end

#sectionsObject (readonly)

Returns the value of attribute sections.



9
10
11
# File 'lib/grit/merge.rb', line 9

def sections
  @sections
end

#textObject (readonly)

Returns the value of attribute text.



9
10
11
# File 'lib/grit/merge.rb', line 9

def text
  @text
end

Instance Method Details

#inspectObject

Pretty object inspection



40
41
42
# File 'lib/grit/merge.rb', line 40

def inspect
  %Q{#<Grit::Merge}
end