Class: WCC::Differ
- Inherits:
-
Object
- Object
- WCC::Differ
- Defined in:
- lib/wcc/diff.rb
Instance Attribute Summary collapse
-
#di ⇒ Object
readonly
Returns the value of attribute di.
Instance Method Summary collapse
- #compute_hilite ⇒ Object
-
#initialize(dstring) ⇒ Differ
constructor
A new instance of Differ.
- #ncharsc ⇒ Object
- #ndeletions ⇒ Object
- #nhunks ⇒ Object
- #ninsertions ⇒ Object
- #nlinesc ⇒ Object
- #rchar ⇒ Object
- #to_s ⇒ Object
Constructor Details
Instance Attribute Details
#di ⇒ Object (readonly)
Returns the value of attribute di.
100 101 102 |
# File 'lib/wcc/diff.rb', line 100 def di @di end |
Instance Method Details
#compute_hilite ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/wcc/diff.rb', line 107 def compute_hilite # get representional string for the whole diff s = rchar #puts s mds = [] md = s.match(/(@|_)di(@|_)/) while not md.nil? mds << md s = s.substring(md.begin(2)) md = s.match(/(@|_)di(@|_)/) end offset = 0 mds.each do |md| i = offset+md.begin(1)+1 offset = md.begin(2)+1 # found a single insertion/deletion pair InLineDiffer.new(@di[i], @di[i+1]).compute_hilite end end |
#ncharsc ⇒ Object
144 145 146 |
# File 'lib/wcc/diff.rb', line 144 def ncharsc @di.inject(0) { |sum,o| sum += (o.hilite.nil? ? 0 : o.hilite.select { |e| not e.nil? }.size) } end |
#ndeletions ⇒ Object
136 137 138 |
# File 'lib/wcc/diff.rb', line 136 def ndeletions @di.inject(0) { |sum,o| sum += (o.status == :del ? 1 : 0) } end |
#nhunks ⇒ Object
128 129 130 |
# File 'lib/wcc/diff.rb', line 128 def nhunks @di.inject(0) { |sum,o| sum += (o.status == :range ? 1 : 0) } end |
#ninsertions ⇒ Object
132 133 134 |
# File 'lib/wcc/diff.rb', line 132 def ninsertions @di.inject(0) { |sum,o| sum += (o.status == :ins ? 1 : 0) } end |
#nlinesc ⇒ Object
140 141 142 |
# File 'lib/wcc/diff.rb', line 140 def nlinesc ninsertions + ndeletions end |
#rchar ⇒ Object
148 149 150 |
# File 'lib/wcc/diff.rb', line 148 def rchar @di.map { |o| o.rchar }.join end |
#to_s ⇒ Object
152 153 154 |
# File 'lib/wcc/diff.rb', line 152 def to_s @di.map { |o| o.to_s }.join("\n") end |