Sha256: 760c4a4925513f4d3c2ca799e6e3fb3b533374020e73898eec4646b341095a9c

Contents?: true

Size: 962 Bytes

Versions: 27

Compression:

Stored size: 962 Bytes

Contents

module Grit
  
  class Merge
    
    STATUS_BOTH = 'both'
    STATUS_OURS = 'ours'
    STATUS_THEIRS = 'theirs'
    
    attr_reader :conflicts, :text, :sections
    
    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
    
    # Pretty object inspection
    def inspect
      %Q{#<Grit::Merge}
    end
  end # Merge
  
end # Grit

Version data entries

27 entries across 27 versions & 12 rubygems

Version Path
boof-grit-1.1.2 lib/grit/merge.rb
davetron5000-grit-1.1.2 lib/grit/merge.rb
davetron5000-grit-1.1.3 lib/grit/merge.rb
joelmoss-grit-1.1.4 lib/grit/merge.rb
joelmoss-grit-1.1.5 lib/grit/merge.rb
joelmoss-grit-1.1.6 lib/grit/merge.rb
kubicek-grit-1.0.3 lib/grit/merge.rb
kubicek-grit-1.1.1.1 lib/grit/merge.rb
kubicek-grit-1.1.1 lib/grit/merge.rb
mojombo-grit-1.1.1 lib/grit/merge.rb
robinluckey-grit-1.1.1 lib/grit/merge.rb
schacon-grit-1.1.1 lib/grit/merge.rb
square-circle-triangle-grit-1.1.2 lib/grit/merge.rb
square-circle-triangle-grit-1.1.3 lib/grit/merge.rb
square-circle-triangle-grit-1.1.4 lib/grit/merge.rb
steveh-grit-1.1.1 lib/grit/merge.rb
tekkub-fugit-0.0.6 lib/grit/lib/grit/merge.rb
tekkub-fugit-0.0.7 lib/grit/lib/grit/merge.rb
ginst-2009.12.8 vendor/gems/grit-1.1.1/lib/grit/merge.rb
ginst-2009.11.24 vendor/gems/grit-1.1.1/lib/grit/merge.rb