class Coopy::HighlightPatch

Attributes

actions[RW]
cell_info[RW]
cmods[RW]
col_permutation[RW]
col_permutation_rev[RW]
csv[RW]
current_row[RW]
dest_in_patch_col[RW]
finished_columns[RW]
flags[RW]
have_dropped_columns[RW]
header[RW]
header_move[RW]
header_post[RW]
header_pre[RW]
header_rename[RW]
header_row[RW]
indexes[RW]
last_source_row[RW]
meta[RW]
meta_change[RW]
modifier[RW]
mods[RW]
next_meta[RW]
patch[RW]
patch_in_dest_col[RW]
patch_in_source_col[RW]
patch_in_source_row[RW]
payload_col[RW]
payload_top[RW]
preamble_row[RW]
prev_meta[RW]
process_meta[RW]
rc_offset[RW]
row_info[RW]
row_permutation[RW]
row_permutation_rev[RW]
source[RW]
source_in_patch_col[RW]
source_view[RW]
view[RW]

Public Class Methods

new(source,patch,flags = nil) click to toggle source
# File lib/lib/coopy/highlight_patch.rb, line 7
def initialize(source,patch,flags = nil)
  @source = source
  @patch = patch
  @flags = flags
  @flags = ::Coopy::CompareFlags.new if flags == nil
  @view = patch.get_cell_view
  @source_view = source.get_cell_view
  @meta = source.get_meta
end

Public Instance Methods

apply() click to toggle source
# File lib/lib/coopy/highlight_patch.rb, line 100
def apply 
  self.reset
  return true if @patch.get_width < 2
  return true if @patch.get_height < 1
  @payload_col = 1 + @rc_offset
  @payload_top = @patch.get_width
  corner = @patch.get_cell_view.to_s(@patch.get_cell(0,0))
  if corner == "@:@" 
    @rc_offset = 1
  else 
    @rc_offset = 0
  end
  begin
    _g1 = 0
    _g = @patch.get_height
    while(_g1 < _g) 
      r = _g1
      _g1+=1
      str = @view.to_s(@patch.get_cell(@rc_offset,r))
      @actions.push(((str != nil) ? str : ""))
    end
  end
  @preamble_row = @header_row = @rc_offset
  begin
    _g11 = 0
    _g2 = @patch.get_height
    while(_g11 < _g2) 
      r1 = _g11
      _g11+=1
      self.apply_row(r1)
    end
  end
  self.finish_columns
  self.finish_rows
  true
end
get_row_string(c) click to toggle source
# File lib/lib/coopy/highlight_patch.rb, line 514
def get_row_string(c)
  at = @source_in_patch_col[c]
  return "NOT_FOUND" if at == nil
  self.get_pre_string(self.get_string(at))
end
is_preamble() click to toggle source
# File lib/lib/coopy/highlight_patch.rb, line 520
def is_preamble 
  @current_row <= @preamble_row
end

Protected Instance Methods

apply_action(code) click to toggle source
# File lib/lib/coopy/highlight_patch.rb, line 464
def apply_action(code)
  if self.use_meta_for_row_changes 
    self.apply_action_external(code)
    return
  end
  mod = ::Coopy::HighlightPatchUnit.new
  mod.code = code
  mod.add = code == "+++"
  mod.rem = code == "---"
  mod.update = code == "->"
  self.need_source_index
  @last_source_row = self.look_up(-1) if @last_source_row == -1
  mod.source_prev_row = @last_source_row
  next_act = @actions[@current_row + 1]
  mod.source_next_row = self.look_up(1) if next_act != "+++" && next_act != "..."
  if mod.add 
    if @actions[@current_row - 1] != "+++" 
      if @actions[@current_row - 1] == "@@" 
        mod.source_prev_row = 0
        @last_source_row = 0
      else 
        mod.source_prev_row = self.look_up(-1)
      end
    end
    mod.source_row = mod.source_prev_row
    mod.source_row_offset = 1 if mod.source_row != -1
  else 
    mod.source_row = @last_source_row = self.look_up
  end
  @last_source_row = mod.source_next_row if @actions[@current_row + 1] == ""
  mod.patch_row = @current_row
  mod.source_row = 0 if code == "@@"
  @mods.push(mod)
end
apply_action_external(code) click to toggle source
# File lib/lib/coopy/highlight_patch.rb, line 402
def apply_action_external(code)
  return if code == "@@"
  rc = ::Coopy::RowChange.new
  rc.action = code
  self.check_act
  rc.cond = {} if code != "+++"
  rc.val = {} if code != "---"
  have_column = false
  begin
    _g1 = @payload_col
    _g = @payload_top
    while(_g1 < _g) 
      i = _g1
      _g1+=1
      prev_name = @header[i]
      name = prev_name
      name = @header_rename[prev_name] if @header_rename.include?(prev_name)
      cact = @modifier[i]
      next if cact == "..."
      next if name == nil || name == ""
      txt = @csv.parse_cell(self.get_string_null(i))
      updated = false
      if @row_info.updated 
        self.get_pre_string(txt)
        updated = @cell_info.updated
      end
      if cact == "+++" && code != "---" 
        if txt != nil && txt != "" 
          rc.val = {} if rc.val == nil
          rc.val[name] = txt
          have_column = true
        end
      end
      if updated 
        begin
          value = @csv.parse_cell(@cell_info.lvalue)
          begin
            value1 = value
            rc.cond[name] = value1
          end
        end
        begin
          value2 = @csv.parse_cell(@cell_info.rvalue)
          begin
            value3 = value2
            rc.val[name] = value3
          end
        end
      elsif code == "+++" 
        rc.val[name] = txt if cact != "---"
      elsif cact != "+++" && cact != "---" 
        rc.cond[name] = txt
      end
    end
  end
  if rc.action == "+" 
    return if !have_column
    rc.action = "->"
  end
  @meta.change_row(rc)
end
apply_header() click to toggle source
# File lib/lib/coopy/highlight_patch.rb, line 315
def apply_header 
  begin
    _g1 = @payload_col
    _g = @payload_top
    while(_g1 < _g) 
      i = _g1
      _g1+=1
      name = self.get_string(i)
      if name == "..." 
        @modifier[i] = "..."
        @have_dropped_columns = true
        next
      end
      mod = @modifier[i]
      move = false
      if mod != nil 
        if (mod[0].ord rescue nil) == 58 
          move = true
          mod = mod[1,mod.length]
        end
      end
      @header[i] = name
      if mod != nil 
        if (mod[0].ord rescue nil) == 40 
          prev_name = mod[1,mod.length - 2]
          @header_pre[prev_name] = i
          @header_post[name] = i
          @header_rename[prev_name] = name
          next
        end
      end
      @header_pre[name] = i if mod != "+++"
      @header_post[name] = i if mod != "---"
      if move 
        @header_move = {} if @header_move == nil
        @header_move[name] = 1
      end
    end
  end
  if !self.use_meta_for_row_changes 
    self.apply_action("+++") if @source.get_height == 0
  end
end
apply_meta() click to toggle source
# File lib/lib/coopy/highlight_patch.rb, line 303
def apply_meta 
  _g1 = @payload_col
  _g = @payload_top
  while(_g1 < _g) 
    i = _g1
    _g1+=1
    name = self.get_string(i)
    next if name == ""
    @modifier[i] = name
  end
end
apply_meta_row(code) click to toggle source
# File lib/lib/coopy/highlight_patch.rb, line 205
def apply_meta_row(code)
  self.need_source_columns
  codes = code.split("@")
  prop_name = ""
  prop_name = codes[codes.length - 2] if codes.length > 1
  code = codes[codes.length - 1] if codes.length > 0
  @prev_meta = {} if @prev_meta == nil
  @next_meta = {} if @next_meta == nil
  begin
    _g1 = @payload_col
    _g = @payload_top
    while(_g1 < _g) 
      i = _g1
      _g1+=1
      txt = self.get_datum(i)
      idx_patch = i
      idx_src = nil
      if @patch_in_source_col.include?(idx_patch) 
        idx_src = @patch_in_source_col[idx_patch]
      else 
        idx_src = -1
      end
      prev_name = nil
      name = nil
      prev_name = @source.get_cell(idx_src,0) if idx_src != -1
      name = @header[idx_patch] if @header.include?(idx_patch)
      ::Coopy::DiffRender.examine_cell(0,0,@view,txt,"",code,"",@cell_info)
      if @cell_info.updated 
        self.set_meta_prop(@prev_meta,prev_name,prop_name,@cell_info.lvalue)
        self.set_meta_prop(@next_meta,name,prop_name,@cell_info.rvalue)
      else 
        self.set_meta_prop(@prev_meta,prev_name,prop_name,@cell_info.value)
        self.set_meta_prop(@next_meta,name,prop_name,@cell_info.value)
      end
    end
  end
end
apply_row(r) click to toggle source
# File lib/lib/coopy/highlight_patch.rb, line 243
def apply_row(r)
  @current_row = r
  code = @actions[r]
  done = false
  if r == 0 && @rc_offset > 0 
    done = true
  elsif code == "@@" 
    @preamble_row = @header_row = r
    self.apply_header
    self.apply_action("@@")
    done = true
  elsif code == "!" 
    @preamble_row = @header_row = r
    self.apply_meta
    done = true
  elsif (code.index("@",nil || 0) || -1) == 0 
    @flags.add_warning("cannot usefully apply diffs with metadata yet: '" + _hx_str(code) + "'")
    @preamble_row = r
    self.apply_meta_row(code)
    if @process_meta 
      codes = code.split("@")
      code = codes[codes.length - 1] if codes.length > 0
    else 
      @meta_change = true
      done = true
    end
    @meta_change = true
    done = true
  end
  return if @process_meta
  if !done 
    self.finish_columns
    if code == "+++" 
      self.apply_action(code)
    elsif code == "---" 
      self.apply_action(code)
    elsif code == "+" || code == ":" 
      self.apply_action(code)
    elsif (code.index("->",nil || 0) || -1) >= 0 
      self.apply_action("->")
    else 
      @last_source_row = -1
    end
  end
end
check_act() click to toggle source
# File lib/lib/coopy/highlight_patch.rb, line 499
def check_act 
  act = self.get_string(@rc_offset)
  ::Coopy::DiffRender.examine_cell(0,0,@view,act,"",act,"",@row_info) if @row_info.value != act
end
compute_ordering(mods,permutation,permutation_rev,dim) click to toggle source
# File lib/lib/coopy/highlight_patch.rb, line 605
def compute_ordering(mods,permutation,permutation_rev,dim)
  to_unit = {}
  from_unit = {}
  meta_from_unit = {}
  ct = 0
  begin
    _g = 0
    while(_g < mods.length) 
      mod = mods[_g]
      _g+=1
      next if mod.add || mod.rem
      next if mod.source_row < 0
      if mod.source_prev_row >= 0 
        begin
          v = mod.source_row
          to_unit[mod.source_prev_row] = v
          v
        end
        begin
          v1 = mod.source_prev_row
          from_unit[mod.source_row] = v1
          v1
        end
        ct+=1 if mod.source_prev_row + 1 != mod.source_row
      end
      if mod.source_next_row >= 0 
        begin
          v2 = mod.source_next_row
          to_unit[mod.source_row] = v2
          v2
        end
        begin
          v3 = mod.source_row
          from_unit[mod.source_next_row] = v3
          v3
        end
        ct+=1 if mod.source_row + 1 != mod.source_next_row
      end
    end
  end
  if ct > 0 
    cursor = nil
    logical = nil
    starts = []
    begin
      _g1 = 0
      while(_g1 < dim) 
        i = _g1
        _g1+=1
        u = from_unit[i]
        if u != nil 
          begin
            meta_from_unit[u] = i
            i
          end
        else 
          starts.push(i)
        end
      end
    end
    used = {}
    len = 0
    begin
      _g2 = 0
      while(_g2 < dim) 
        i1 = _g2
        _g2+=1
        if logical != nil && meta_from_unit.include?(logical) 
          cursor = meta_from_unit[logical]
        else 
          cursor = nil
        end
        if cursor == nil 
          v4 = starts.shift
          cursor = v4
          logical = v4
        end
        cursor = 0 if cursor == nil
        while(used.include?(cursor)) 
          cursor = ((cursor + 1).remainder(dim) rescue Float::NAN)
        end
        logical = cursor
        permutation_rev.push(cursor)
        begin
          used[cursor] = 1
          1
        end
      end
    end
    begin
      _g11 = 0
      _g3 = permutation_rev.length
      while(_g11 < _g3) 
        i2 = _g11
        _g11+=1
        permutation[i2] = -1
      end
    end
    begin
      _g12 = 0
      _g4 = permutation.length
      while(_g12 < _g4) 
        i3 = _g12
        _g12+=1
        permutation[permutation_rev[i3]] = i3
      end
    end
  end
end
fill_in_new_columns() click to toggle source
# File lib/lib/coopy/highlight_patch.rb, line 721
def fill_in_new_columns 
  _g = 0
  _g1 = @cmods
  while(_g < _g1.length) 
    cmod = _g1[_g]
    _g+=1
    if !cmod.rem 
      if cmod.add 
        begin
          _g2 = 0
          _g3 = @mods
          while(_g2 < _g3.length) 
            mod = _g3[_g2]
            _g2+=1
            if mod.patch_row != -1 && mod.dest_row != -1 
              d = @patch.get_cell(cmod.patch_row,mod.patch_row)
              @source.set_cell(cmod.dest_row,mod.dest_row,d)
            end
          end
        end
        hdr = @header[cmod.patch_row]
        @source.set_cell(cmod.dest_row,0,@view.to_datum(hdr))
      end
    end
  end
end
finish_columns() click to toggle source
# File lib/lib/coopy/highlight_patch.rb, line 825
def finish_columns 
  return if @finished_columns
  @finished_columns = true
  self.need_source_columns
  begin
    _g1 = @payload_col
    _g = @payload_top
    while(_g1 < _g) 
      i = _g1
      _g1+=1
      act = @modifier[i]
      hdr = @header[i]
      act = "" if act == nil
      if act == "---" 
        at = -1
        at = @patch_in_source_col[i] if @patch_in_source_col.include?(i)
        mod = ::Coopy::HighlightPatchUnit.new
        mod.code = act
        mod.rem = true
        mod.source_row = at
        mod.patch_row = i
        @cmods.push(mod)
      elsif act == "+++" 
        mod1 = ::Coopy::HighlightPatchUnit.new
        mod1.code = act
        mod1.add = true
        prev = -1
        cont = false
        mod1.source_row = -1
        mod1.source_row = @cmods[@cmods.length - 1].source_row if @cmods.length > 0
        mod1.source_row_offset = 1 if mod1.source_row != -1
        mod1.patch_row = i
        @cmods.push(mod1)
      elsif act != "..." 
        at1 = -1
        at1 = @patch_in_source_col[i] if @patch_in_source_col.include?(i)
        mod2 = ::Coopy::HighlightPatchUnit.new
        mod2.code = act
        mod2.patch_row = i
        mod2.source_row = at1
        @cmods.push(mod2)
      end
    end
  end
  at2 = -1
  rat = -1
  begin
    _g11 = 0
    _g2 = @cmods.length - 1
    while(_g11 < _g2) 
      i1 = _g11
      _g11+=1
      icode = @cmods[i1].code
      at2 = @cmods[i1].source_row if icode != "+++" && icode != "---"
      @cmods[i1 + 1].source_prev_row = at2
      j = @cmods.length - 1 - i1
      jcode = @cmods[j].code
      rat = @cmods[j].source_row if jcode != "+++" && jcode != "---"
      @cmods[j - 1].source_next_row = rat
    end
  end
  fate = Array.new
  self.permute_columns
  if @header_move != nil 
    if @col_permutation.length > 0 
      begin
        _g3 = 0
        _g12 = @cmods
        while(_g3 < _g12.length) 
          mod3 = _g12[_g3]
          _g3+=1
          mod3.source_row = @col_permutation[mod3.source_row] if mod3.source_row >= 0
        end
      end
      @source.insert_or_delete_columns(@col_permutation,@col_permutation.length) if !self.use_meta_for_column_changes
    end
  end
  len = self.process_mods(@cmods,fate,@source.get_width)
  if !self.use_meta_for_column_changes 
    @source.insert_or_delete_columns(fate,len)
    return
  end
  changed = false
  begin
    _g4 = 0
    _g13 = @cmods
    while(_g4 < _g13.length) 
      mod4 = _g13[_g4]
      _g4+=1
      if mod4.code != "" 
        changed = true
        break
      end
    end
  end
  return if !changed
  columns = Array.new
  target = {}
  inc = lambda {|x|
    if x < 0 
      return x
    else 
      return x + 1
    end
  }
  begin
    _g14 = 0
    _g5 = fate.length
    while(_g14 < _g5) 
      i2 = _g14
      _g14+=1
      begin
        value = (inc).call(fate[i2])
        target[i2] = value
      end
    end
  end
  self.need_source_columns
  self.need_dest_columns
  begin
    _g15 = 1
    _g6 = @patch.get_width
    while(_g15 < _g6) 
      idx_patch = _g15
      _g15+=1
      change = ::Coopy::ColumnChange.new
      idx_src = nil
      if @patch_in_source_col.include?(idx_patch) 
        idx_src = @patch_in_source_col[idx_patch]
      else 
        idx_src = -1
      end
      prev_name = nil
      name = nil
      prev_name = @source.get_cell(idx_src,0) if idx_src != -1
      if @modifier[idx_patch] != "---" 
        name = @header[idx_patch] if @header.include?(idx_patch)
      end
      change.prev_name = prev_name
      change.name = name
      if @next_meta != nil 
        change.props = @next_meta[name] if @next_meta.include?(name)
      end
      columns.push(change)
    end
  end
  @meta.alter_columns(columns)
end
finish_rows() click to toggle source
# File lib/lib/coopy/highlight_patch.rb, line 748
def finish_rows 
  return if self.use_meta_for_row_changes
  if @source.get_width == 0 
    @source.resize(0,0) if @source.get_height != 0
    return
  end
  fate = Array.new
  self.permute_rows
  if @row_permutation.length > 0 
    _g = 0
    _g1 = @mods
    while(_g < _g1.length) 
      mod = _g1[_g]
      _g+=1
      mod.source_row = @row_permutation[mod.source_row] if mod.source_row >= 0
    end
  end
  @source.insert_or_delete_rows(@row_permutation,@row_permutation.length) if @row_permutation.length > 0
  len = self.process_mods(@mods,fate,@source.get_height)
  @source.insert_or_delete_rows(fate,len)
  self.need_dest_columns
  begin
    _g2 = 0
    _g11 = @mods
    while(_g2 < _g11.length) 
      mod1 = _g11[_g2]
      _g2+=1
      if !mod1.rem 
        if mod1.add 
          _it = ::Rb::RubyIterator.new(@header_post.values)
          while(_it.has_next) do
            c = _it._next
            offset = @patch_in_dest_col[c]
            @source.set_cell(offset,mod1.dest_row,@patch.get_cell(c,mod1.patch_row)) if offset != nil && offset >= 0
          end
        elsif mod1.update 
          @current_row = mod1.patch_row
          self.check_act
          next if !@row_info.updated
          _it2 = ::Rb::RubyIterator.new(@header_pre.values)
          while(_it2.has_next) do
            c1 = _it2._next
            txt = @view.to_s(@patch.get_cell(c1,mod1.patch_row))
            ::Coopy::DiffRender.examine_cell(0,0,@view,txt,"",@row_info.value,"",@cell_info)
            next if !@cell_info.updated
            next if @cell_info.conflicted
            d = @view.to_datum(@csv.parse_cell(@cell_info.rvalue))
            offset1 = @patch_in_dest_col[c1]
            @source.set_cell(@patch_in_dest_col[c1],mod1.dest_row,d) if offset1 != nil && offset1 >= 0
          end
        end
      end
    end
  end
  self.fill_in_new_columns
  begin
    _g12 = 0
    _g3 = @source.get_width
    while(_g12 < _g3) 
      i = _g12
      _g12+=1
      name = @view.to_s(@source.get_cell(i,0))
      next_name = @header_rename[name]
      next if next_name == nil
      @source.set_cell(i,0,@view.to_datum(next_name))
    end
  end
end
get_datum(c) click to toggle source
# File lib/lib/coopy/highlight_patch.rb, line 289
def get_datum(c)
  @patch.get_cell(c,@current_row)
end
get_pre_string(txt) click to toggle source
# File lib/lib/coopy/highlight_patch.rb, line 504
def get_pre_string(txt)
  self.check_act
  return txt if !@row_info.updated
  ::Coopy::DiffRender.examine_cell(0,0,@view,txt,"",@row_info.value,"",@cell_info)
  return txt if !@cell_info.updated
  @cell_info.lvalue
end
get_string(c) click to toggle source
# File lib/lib/coopy/highlight_patch.rb, line 293
def get_string(c)
  @view.to_s(self.get_datum(c))
end
get_string_null(c) click to toggle source
# File lib/lib/coopy/highlight_patch.rb, line 297
def get_string_null(c)
  d = self.get_datum(c)
  return nil if d == nil
  @view.to_s(d)
end
look_up(del = 0) click to toggle source
# File lib/lib/coopy/highlight_patch.rb, line 359
def look_up(del = 0)
  return @patch_in_source_row[@current_row + del] if @patch_in_source_row.include?(@current_row + del)
  result = -1
  @current_row += del
  if @current_row >= 0 && @current_row < @patch.get_height 
    _g = 0
    _g1 = @indexes
    while(_g < _g1.length) 
      idx = _g1[_g]
      _g+=1
      match = idx.query_by_content(self)
      next if match.spot_a == 0
      if match.spot_a == 1 
        result = match.item_a.lst[0]
        break
      end
      if @current_row > 0 
        prev = @patch_in_source_row[@current_row - 1]
        if prev != nil 
          lst = match.item_a.lst
          begin
            _g2 = 0
            while(_g2 < lst.length) 
              row = lst[_g2]
              _g2+=1
              if row == prev + 1 
                result = row
                break
              end
            end
          end
        end
      end
    end
  end
  begin
    @patch_in_source_row[@current_row] = result
    result
  end
  @current_row -= del
  result
end
need_dest_columns() click to toggle source
# File lib/lib/coopy/highlight_patch.rb, line 159
def need_dest_columns 
  return if @patch_in_dest_col != nil
  @patch_in_dest_col = {}
  @dest_in_patch_col = {}
  begin
    _g = 0
    _g1 = @cmods
    while(_g < _g1.length) 
      cmod = _g1[_g]
      _g+=1
      if cmod.patch_row != -1 
        @patch_in_dest_col[cmod.patch_row] = cmod.dest_row
        @dest_in_patch_col[cmod.dest_row] = cmod.patch_row
      end
    end
  end
end
need_source_columns() click to toggle source
# File lib/lib/coopy/highlight_patch.rb, line 139
def need_source_columns 
  return if @source_in_patch_col != nil
  @source_in_patch_col = {}
  @patch_in_source_col = {}
  av = @source.get_cell_view
  begin
    _g1 = 0
    _g = @source.get_width
    while(_g1 < _g) 
      i = _g1
      _g1+=1
      name = av.to_s(@source.get_cell(i,0))
      at = @header_pre[name]
      next if at == nil
      @source_in_patch_col[i] = at
      @patch_in_source_col[at] = i
    end
  end
end
need_source_index() click to toggle source
# File lib/lib/coopy/highlight_patch.rb, line 177
def need_source_index 
  return if @indexes != nil
  state = ::Coopy::TableComparisonState.new
  state.a = @source
  state.b = @source
  comp = ::Coopy::CompareTable.new(state)
  comp.store_indexes
  comp.run
  comp.align
  @indexes = comp.get_indexes
  self.need_source_columns
end
permute_columns() click to toggle source
# File lib/lib/coopy/highlight_patch.rb, line 817
def permute_columns 
  return if @header_move == nil
  @col_permutation = Array.new
  @col_permutation_rev = Array.new
  self.compute_ordering(@cmods,@col_permutation,@col_permutation_rev,@source.get_width)
  return if @col_permutation.length == 0
end
permute_rows() click to toggle source
# File lib/lib/coopy/highlight_patch.rb, line 715
def permute_rows 
  @row_permutation = Array.new
  @row_permutation_rev = Array.new
  self.compute_ordering(@mods,@row_permutation,@row_permutation_rev,@source.get_height)
end
process_mods(rmods,fate,len) click to toggle source
# File lib/lib/coopy/highlight_patch.rb, line 538
def process_mods(rmods,fate,len)
  rmods.sort!{|a,b| self.sort_mods(a,b)}
  offset = 0
  last = -1
  target = 0
  if rmods.length > 0 
    last = 0 if rmods[0].source_prev_row == -1
  end
  begin
    _g = 0
    while(_g < rmods.length) 
      mod = rmods[_g]
      _g+=1
      if last != -1 
        _g2 = last
        _g1 = mod.source_row + mod.source_row_offset
        while(_g2 < _g1) 
          i = _g2
          _g2+=1
          fate.push(i + offset)
          target+=1
          last+=1
        end
      end
      if mod.rem 
        fate.push(-1)
        offset-=1
      elsif mod.add 
        mod.dest_row = target
        target+=1
        offset+=1
      else 
        mod.dest_row = target
      end
      if mod.source_row >= 0 
        last = mod.source_row + mod.source_row_offset
        last+=1 if mod.rem
      elsif mod.add && mod.source_next_row != -1 
        last = mod.source_next_row + mod.source_row_offset
      elsif mod.rem || mod.add 
        last = -1
      end
    end
  end
  if last != -1 
    _g3 = last
    while(_g3 < len) 
      i1 = _g3
      _g3+=1
      fate.push(i1 + offset)
      target+=1
      last+=1
    end
  end
  len + offset
end
reset() click to toggle source
# File lib/lib/coopy/highlight_patch.rb, line 61
def reset 
  @header = {}
  @header_pre = {}
  @header_post = {}
  @header_rename = {}
  @header_move = nil
  @modifier = {}
  @mods = Array.new
  @cmods = Array.new
  @csv = ::Coopy::Csv.new
  @rc_offset = 0
  @current_row = -1
  @row_info = ::Coopy::CellInfo.new
  @cell_info = ::Coopy::CellInfo.new
  @source_in_patch_col = @patch_in_source_col = @patch_in_dest_col = nil
  @patch_in_source_row = {}
  @indexes = nil
  @last_source_row = -1
  @actions = Array.new
  @row_permutation = nil
  @row_permutation_rev = nil
  @col_permutation = nil
  @col_permutation_rev = nil
  @have_dropped_columns = false
  @header_row = 0
  @preamble_row = 0
  @meta_change = false
  @process_meta = false
  @prev_meta = nil
  @next_meta = nil
  @finished_columns = false
end
set_meta_prop(target,column_name,prop_name,value) click to toggle source
# File lib/lib/coopy/highlight_patch.rb, line 190
def set_meta_prop(target,column_name,prop_name,value)
  return if column_name == nil
  return if prop_name == nil
  if !target.include?(column_name) 
    value1 = Array.new
    target[column_name] = value1
  end
  change = ::Coopy::PropertyChange.new
  change.prev_name = prop_name
  change.name = prop_name
  value = nil if value == ""
  change.val = value
  target[column_name].push(change)
end
sort_mods(a,b) click to toggle source
# File lib/lib/coopy/highlight_patch.rb, line 526
def sort_mods(a,b)
  return 1 if b.code == "@@" && a.code != "@@"
  return -1 if a.code == "@@" && b.code != "@@"
  return 1 if a.source_row == -1 && !a.add && b.source_row != -1
  return -1 if a.source_row != -1 && !b.add && b.source_row == -1
  return 1 if a.source_row + a.source_row_offset > b.source_row + b.source_row_offset
  return -1 if a.source_row + a.source_row_offset < b.source_row + b.source_row_offset
  return 1 if a.patch_row > b.patch_row
  return -1 if a.patch_row < b.patch_row
  0
end
use_meta_for_column_changes() click to toggle source
# File lib/lib/coopy/highlight_patch.rb, line 595
def use_meta_for_column_changes 
  return false if @meta == nil
  @meta.use_for_column_changes
end
use_meta_for_row_changes() click to toggle source
# File lib/lib/coopy/highlight_patch.rb, line 600
def use_meta_for_row_changes 
  return false if @meta == nil
  @meta.use_for_row_changes
end