Module: HTMLCollapsable

Included in:
Array, String
Defined in:
lib/emaildiff.rb

Instance Method Summary collapse

Instance Method Details

#diff(b) ⇒ Object



44
45
46
# File 'lib/emaildiff.rb', line 44

def diff(b)
  Diff.new(self, b)
end

#patch_email(diff, starttoken = nil, endtoken = nil) ⇒ Object



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
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
# File 'lib/emaildiff.rb', line 48

def patch_email(diff,starttoken = nil,endtoken = nil)
  found_diff = 0
  newary = diff.difftype.new
  ai = 0
  bi = 0
  diff.diffs.each { |d|
    d.each { |mod|
      quoted = 0
	case mod[0]
	when '-'
 if ai < mod[1] && !starttoken.nil? && found_diff == 1
          quoted = 1
        end
        newary << starttoken if quoted == 1
 while ai < mod[1]
   newary << diff.orig_b[bi] if quoted == 1 || found_diff == 0
   ai += 1
   bi += 1
 end
 newary << endtoken if quoted == 1
 ai += 1
	when '+'
 if bi < mod[1] && !starttoken.nil? && found_diff == 1
          quoted = 1
        end
        newary << starttoken if quoted == 1
 while bi < mod[1]
   newary << diff.orig_b[bi] if quoted == 1 || found_diff == 0
   ai += 1
   bi += 1
 end
 newary << endtoken if quoted == 1
 newary << diff.orig_b[mod[1]]
        found_diff = 1
 bi += 1
	else
 raise "Unknown diff action"
	end
    }
  }
  quoted = 0
  if ai < self.length && !starttoken.nil? && found_diff == 1
    quoted = 1
  end
  newary << starttoken if quoted == 1
  while ai < self.length
    newary << diff.orig_b[bi] if quoted == 1 or found_diff == 0
    ai += 1
    bi += 1
  end
  newary << endtoken if quoted == 1
  if found_diff == 0
    if !starttoken.nil?
      if newary.length > 0 
        newary.unshift starttoken
        newary << endtoken
      end
    else
      return diff.difftype.new
    end
  end
  return newary
end