Class: WikiAnnotate
- Inherits:
-
Object
- Object
- WikiAnnotate
- Defined in:
- app/models/wiki_page.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#lines ⇒ Object
readonly
Returns the value of attribute lines.
Instance Method Summary collapse
-
#initialize(content) ⇒ WikiAnnotate
constructor
A new instance of WikiAnnotate.
Constructor Details
#initialize(content) ⇒ WikiAnnotate
Returns a new instance of WikiAnnotate.
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'app/models/wiki_page.rb', line 183 def initialize(content) @content = content current = content current_lines = current.text.split(/\r?\n/) @lines = current_lines.collect {|t| [nil, nil, t]} positions = [] current_lines.size.times {|i| positions << i} while (current.previous) d = current.previous.text.split(/\r?\n/).diff(current.text.split(/\r?\n/)).diffs.flatten d.each_slice(3) do |s| sign, line = s[0], s[1] if sign == '+' && positions[line] && positions[line] != -1 if @lines[positions[line]][0].nil? @lines[positions[line]][0] = current.version @lines[positions[line]][1] = current. end end end d.each_slice(3) do |s| sign, line = s[0], s[1] if sign == '-' positions.insert(line, -1) else positions[line] = nil end end positions.compact! # Stop if every line is annotated break unless @lines.detect { |line| line[0].nil? } current = current.previous end @lines.each { |line| line[0] ||= current.version } end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
181 182 183 |
# File 'app/models/wiki_page.rb', line 181 def content @content end |
#lines ⇒ Object (readonly)
Returns the value of attribute lines.
181 182 183 |
# File 'app/models/wiki_page.rb', line 181 def lines @lines end |