Class LogiVersionsController
In: app/controllers/logi_versions_controller.rb
Parent: ApplicationController

Methods

Public Instance methods

[Source]

    # File app/controllers/logi_versions_controller.rb, line 30
30:   def diff
31:     if params[:logi_version_A] == params[:logi_version_B]
32:       render :text => @logi.logi_versions.find_by_nr(
33:           params[:logi_version_A]).text
34:     else
35:       @diff_array = self.diff_versions_to_a(@logi,
36:           @logi.logi_versions.find_by_nr(params[:logi_version_A]),
37:           @logi.logi_versions.find_by_nr(params[:logi_version_B]))
38:     end
39:   end

REST-methods

[Source]

    # File app/controllers/logi_versions_controller.rb, line 25
25:   def show
26:     @logi_versions = @logi.logi_versions.sort {|a, b|
27:         b.created_at <=> a.created_at }
28:   end

Protected Instance methods

[Source]

     # File app/controllers/logi_versions_controller.rb, line 130
130:   def clean_h1
131:     a = response.body.split('</h1>')
132:     body = a.pop
133:     response.body = '<h1>' + a.to_s.gsub!('<h1>','') + '</h1>' + body
134:   end

Sub-methods

[Source]

     # File app/controllers/logi_versions_controller.rb, line 45
 45:   def diff_versions_to_a(logi, version_A, version_B)
 46: 
 47:     if version_A.nr > version_B.nr
 48:       new_version = version_A.position_ranges
 49:       old_version = version_B.position_ranges
 50:     else
 51:       new_version = version_B.position_ranges
 52:       old_version = version_A.position_ranges
 53:     end
 54: 
 55:     only_new = new_version - old_version
 56:     only_old = old_version - new_version
 57: 
 58:     adjacent_new = new_version.stack_adjacent
 59:     adjacent_old = old_version.stack_adjacent
 60: 
 61:     both = new_version & old_version
 62: 
 63:     all_AB = PositionRange::List.new
 64: 
 65:     both.each { |p_r|
 66:       p_r.version = 0
 67:       p_r.text = logi.text_stack[p_r]
 68:       new_version.each_with_index do |s_p_r, i|
 69:         if p_r.begin >= s_p_r.begin and p_r.end <= s_p_r.end
 70:           p_r.new_position = PositionRange.new(
 71:               adjacent_new[i].begin + p_r.begin - s_p_r.begin,
 72:               adjacent_new[i].end + p_r.end - s_p_r.end, {})
 73:           break
 74:         end
 75:       end
 76:       old_version.each_with_index do |s_p_r, i|
 77:         if p_r.begin >= s_p_r.begin and p_r.end <= s_p_r.end
 78:           p_r.old_position = PositionRange.new(
 79:               adjacent_old[i].begin + p_r.begin - s_p_r.begin,
 80:               adjacent_old[i].end + p_r.end - s_p_r.end, {})
 81:           break
 82:         end
 83:       end
 84:       all_AB << p_r
 85:     }
 86:     i = 0
 87:     only_old.each { |p_r|
 88:       p_r.version = -1
 89:       p_r.text = logi.text_stack[p_r]
 90:       old_version.each_with_index do |s_p_r, i|
 91:         if p_r.begin >= s_p_r.begin and p_r.end <= s_p_r.end
 92:           p_r.old_position = PositionRange.new(
 93:               adjacent_old[i].begin + p_r.begin - s_p_r.begin, 
 94:               adjacent_old[i].end + p_r.end - s_p_r.end, {})
 95:           break
 96:         end
 97:       end
 98:       while i < all_AB.size and 
 99:           all_AB[i].old_position.begin < p_r.old_position.begin
100:         i += 1
101:       end
102:       all_AB.insert(i,p_r)
103:     }
104:     i = 0
105:     only_new.each { |p_r|
106:       last_p_r = p_r
107:       p_r.version = 1
108:       p_r.text = logi.text_stack[p_r]
109:       new_version.each_with_index do |s_p_r, i|
110:         if p_r.begin >= s_p_r.begin and p_r.end <= s_p_r.end
111:           p_r.new_position = PositionRange.new(
112:               adjacent_new[i].begin + p_r.begin - s_p_r.begin,
113:               adjacent_new[i].end + p_r.end - s_p_r.end, {})
114:           break
115:         end
116:       end
117:       while i < all_AB.size
118:         if all_AB[i].version != -1
119:           if all_AB[i].new_position.begin >= p_r.new_position.begin
120:             break
121:           end
122:         end
123:         i += 1
124:       end
125:       all_AB.insert(i,p_r)
126:     }
127:     return all_AB
128:   end

[Validate]