18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/coopy/diff_parser.rb', line 18
def apply
rows = @rows
render = @diff_output
return if render.nil?
render.begin_diff
rcs = []
columns = DiffColumns.new
rows.each_with_index do |row, r|
row_mode = ""
open = false
next if row.length == 0
txt = row[0]
txt = "" if txt.nil?
if txt=="@" or txt=="@@"
row_mode = "@@"
columns.title_row = row
columns.update
elsif txt=="!" or txt=="+++" or txt=="---" or txt=="..." or txt.include? "->"
row_mode = txt
columns.change_row = row if txt=="!"
else
open = true
end
cmd = txt
cells = []
row.each_with_index do |val, c|
next if c == 0
nval = nil
txt = ""
txt = val.to_s unless val.nil?
txt = "" if txt=="NULL"
cell_mode = ""
separator = ""
if open and !columns.change_row.nil?
change = columns.change_row[c]
if change=="+++" or change == "---"
cell_mode = change
end
end
if cmd.to_s.include? "->"
if txt.include? cmd
cell_mode = "->"
separator = cmd
b = txt.index(cmd)
val = txt[0,b]
nval = txt[b+cmd.length,txt.length]
end
end
cells << {
:txt => txt,
:value => val,
:new_value => nval,
:cell_mode => cell_mode,
:separator => separator
}
end
rc = RowChange.new(row_mode,cells)
unless columns.title_row.nil?
rcs.each { |rc| self.apply_row_main(rc,columns) }
rcs = []
self.apply_row_main(rc,columns)
else
rcs << rc
end
end
rcs.each { |rc| self.apply_row_main(rc,columns) }
render.end_diff
end
|