Method: Coopy::DiffRender.examine_cell

Defined in:
lib/coopy/diff_render.rb

.examine_cell(x, y, value, vcol, vrow, vcorner, cell) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/coopy/diff_render.rb', line 66

def self.examine_cell(x, y, value, vcol, vrow, vcorner, cell)  
    cell.category = ""
    cell.category_given_tr = ""
    cell.separator = ""
    cell.conflicted = false
    cell.updated = false
    cell.pvalue = cell.lvalue = cell.rvalue = nil
    cell.value = value
    cell.value = "" if (cell.value.nil?) 
    cell.pretty_value = cell.value
    vrow = "" if (vrow.nil?)
    vcol = "" if (vcol.nil?)
    removed_column = false
    if (vrow == ":") 
        cell.category = 'move'
    end 
    if (vcol.index("+++")) 
        cell.category_given_tr = cell.category = 'add'
    elsif (vcol.index("---")) 
        cell.category_given_tr = cell.category = 'remove'
        removed_column = true
    end
    if (vrow == "!") 
        cell.category = 'spec'
    elsif (vrow == "@@") 
        cell.category = 'header'
    elsif (vrow == "+++") 
        if (!removed_column) 
            cell.category = 'add'
        end
    elsif (vrow == "---") 
        cell.category = "remove"
    elsif (vrow.index("->")) 
        if (!removed_column) 
            tokens = vrow.split("!")
            full = vrow
            part = tokens[1]
            part = full if (part.nil?)
            if (cell.value.index(part)) 
                cat = "modify"
                div = part
                # render with utf8 -> symbol
                if (part!=full) 
                    if (cell.value.index(full)) 
                        div = full
                        cat = "conflict"
                        cell.conflicted = true
                    end
                end
                cell.updated = true
                cell.separator = div
                tokens = cell.pretty_value.split(div)
                pretty_tokens = tokens
                if (tokens.length>=2) 
                    pretty_tokens[0] = mark_spaces(tokens[0],tokens[1])
                    pretty_tokens[1] = mark_spaces(tokens[1],tokens[0])
                end
                if (tokens.length>=3) 
                    ref = pretty_tokens[0]
                    pretty_tokens[0] = mark_spaces(ref,tokens[2])
                    pretty_tokens[2] = mark_spaces(tokens[2],ref)
                end
                if (tokens.length == 0)
                    pretty_tokens = ['','']
                end
                cell.pretty_value = pretty_tokens.join("→")
                cell.category_given_tr = cell.category = cat
                offset = cell.conflicted ? 1 : 0
                cell.lvalue = tokens[offset]
                cell.rvalue = tokens[offset+1]
                cell.pvalue = tokens[0] if (cell.conflicted)
            end
        end
    end
end