Method: ArrayDiff#to_diff

Defined in:
lib/array_diff.rb

#to_diffObject



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/array_diff.rb', line 154

def to_diff
  offset = 0
  @diffs.each { |b|
    first = b[0][1]
    addcount = 0
    remcount = 0
    b.each { |l| 
      if l[0] == "+"
        addcount += 1
      elsif l[0] == "-"
        remcount += 1
      end
    }
    if addcount == 0
      puts "#{diffrange(first+1, first+remcount)}d#{first+offset}"
    elsif remcount == 0
      puts "#{first-offset}a#{diffrange(first+1, first+addcount)}"
    else
      puts "#{diffrange(first+1, first+remcount)}c#{diffrange(first+offset+1, first+offset+addcount)}"
    end
    lastdel = (b[0][0] == "-")
    b.each { |l|
      if l[0] == "-"
        offset -= 1
        print "< "
      elsif l[0] == "+"
        offset += 1
        if lastdel
          lastdel = false
          puts "---"
        end
        print "> "
      end
  print l[2]
  print "\n"
    }
  }
end