class Coopy::TableDiff

Attributes

a[RW]
act[RW]
active_column[RW]
active_row[RW]
align[RW]
allow_delete[RW]
allow_insert[RW]
allow_update[RW]
b[RW]
builder[RW]
col_deletes[RW]
col_inserts[RW]
col_map[RW]
col_moves[RW]
col_renames[RW]
col_reorders[RW]
col_updates[RW]
column_units[RW]
column_units_updated[RW]
conflict_sep[RW]
diff_found[RW]
flags[RW]
has_parent[RW]
have_addition[RW]
have_schema[RW]
is_index_a[RW]
is_index_b[RW]
is_index_p[RW]
nested[RW]
nesting_present[RW]
order[RW]
p[RW]
preserve_columns[RW]
publish[RW]
ra_header[RW]
rb_header[RW]
row_deletes[RW]
row_inserts[RW]
row_map[RW]
row_moves[RW]
row_reorders[RW]
row_units[RW]
row_updates[RW]
rp_header[RW]
schema[RW]
schema_diff_found[RW]
sep[RW]
show_rc_numbers[RW]
top_line_done[RW]
v[RW]

Public Class Methods

new(align,flags) click to toggle source
# File lib/lib/coopy/table_diff.rb, line 7
def initialize(align,flags)
  @align = align
  @flags = flags
  @builder = nil
  @preserve_columns = false
end

Public Instance Methods

get_comparison_state() click to toggle source
# File lib/lib/coopy/table_diff.rb, line 1160
def get_comparison_state 
  return nil if @align == nil
  @align.comp
end
get_summary() click to toggle source
# File lib/lib/coopy/table_diff.rb, line 1165
def get_summary 
  ds = ::Coopy::DiffSummary.new
  ds.row_deletes = @row_deletes
  ds.row_inserts = @row_inserts
  ds.row_updates = @row_updates
  ds.row_reorders = @row_reorders
  ds.col_deletes = @col_deletes
  ds.col_inserts = @col_inserts
  ds.col_updates = @col_updates
  ds.col_renames = @col_renames
  ds.col_reorders = @col_reorders
  ds.row_count_initial_with_header = @align.get_source.get_height
  ds.row_count_final_with_header = @align.get_target.get_height
  ds.row_count_initial = @align.get_source.get_height - @align.get_source_header - 1
  ds.row_count_final = @align.get_target.get_height - @align.get_target_header - 1
  ds.col_count_initial = @align.get_source.get_width
  ds.col_count_final = @align.get_target.get_width
  ds.different = @row_deletes + @row_inserts + @row_updates + @row_reorders + @col_deletes + @col_inserts + @col_updates + @col_renames + @col_reorders > 0
  ds
end
has_difference() click to toggle source
# File lib/lib/coopy/table_diff.rb, line 1148
def has_difference 
  @diff_found
end
has_schema_difference() click to toggle source
# File lib/lib/coopy/table_diff.rb, line 1152
def has_schema_difference 
  @schema_diff_found
end
hilite(output) click to toggle source
# File lib/lib/coopy/table_diff.rb, line 993
def hilite(output)
  output = ::Coopy::Coopy.tablify(output)
  self.hilite_single(output)
end
hilite_with_nesting(output) click to toggle source
# File lib/lib/coopy/table_diff.rb, line 1121
def hilite_with_nesting(output)
  base = output.add("base")
  result = self.hilite_single(base)
  return false if !result
  return true if @align.comp == nil
  order = @align.comp.child_order
  return true if order == nil
  output.alignment = @align
  begin
    _g = 0
    while(_g < order.length) 
      name = order[_g]
      _g+=1
      child = @align.comp.children[name]
      alignment = child.alignment
      if alignment.is_marked_as_identical 
        @align.comp.children[name] = nil
        next
      end
      td = ::Coopy::TableDiff.new(alignment,@flags)
      child_output = output.add(name)
      result = result && td.hilite_single(child_output)
    end
  end
  result
end
is_nested() click to toggle source
# File lib/lib/coopy/table_diff.rb, line 1156
def is_nested 
  @nesting_present
end
set_cell_builder(builder) click to toggle source
# File lib/lib/coopy/table_diff.rb, line 69
def set_cell_builder(builder)
  @builder = builder
end

Protected Instance Methods

add_header(output) click to toggle source
# File lib/lib/coopy/table_diff.rb, line 663
def add_header(output)
  if @flags.always_show_header 
    at = output.get_height
    output.resize(@column_units.length + 1,at + 1)
    output.set_cell(0,at,@builder.marker("@@"))
    begin
      _g1 = 0
      _g = @column_units.length
      while(_g1 < _g) 
        j = _g1
        _g1+=1
        cunit = @column_units[j]
        if cunit.r >= 0 
          output.set_cell(j + 1,at,@b.get_cell(cunit.r,@rb_header)) if @b.get_height != 0
        elsif cunit.l >= 0 
          output.set_cell(j + 1,at,@a.get_cell(cunit.l,@ra_header)) if @a.get_height != 0
        elsif cunit.lp >= 0 
          output.set_cell(j + 1,at,@p.get_cell(cunit.lp,@rp_header)) if @p.get_height != 0
        end
        @col_map[j + 1] = cunit
      end
    end
    @top_line_done = true
  end
end
add_meta(output) click to toggle source
# File lib/lib/coopy/table_diff.rb, line 708
def add_meta(output)
  return false if @a == nil && @b == nil && @p == nil
  return false if !@flags.show_meta
  a_meta = self.get_meta_table(@a)
  b_meta = self.get_meta_table(@b)
  p_meta = self.get_meta_table(@p)
  return false if !self.check_meta(@a,a_meta)
  return false if !self.check_meta(@b,b_meta)
  return false if !self.check_meta(@p,p_meta)
  meta_diff = ::Coopy::SimpleTable.new(0,0)
  meta_flags = ::Coopy::CompareFlags.new
  meta_flags.add_primary_key("@@")
  meta_flags.add_primary_key("@")
  meta_flags.unchanged_column_context = 65536
  meta_flags.unchanged_context = 0
  meta_align = ::Coopy::Coopy.compare_tables3(((a_meta == p_meta) ? nil : p_meta),a_meta,b_meta,meta_flags).align
  td = ::Coopy::TableDiff.new(meta_align,meta_flags)
  td.preserve_columns = true
  td.hilite(meta_diff)
  if td.has_difference || td.has_schema_difference 
    h = output.get_height
    dh = meta_diff.get_height
    offset = nil
    if td.has_schema_difference 
      offset = 2
    else 
      offset = 1
    end
    output.resize(output.get_width,h + dh - offset)
    v = meta_diff.get_cell_view
    begin
      _g = offset
      while(_g < dh) 
        y = _g
        _g+=1
        begin
          _g2 = 1
          _g1 = meta_diff.get_width
          while(_g2 < _g1) 
            x = _g2
            _g2+=1
            c = meta_diff.get_cell(x,y)
            c = "@" + _hx_str(v.to_s(c)) + "@" + _hx_str(v.to_s(meta_diff.get_cell(0,y))) if x == 1
            output.set_cell(x - 1,h + y - offset,c)
          end
        end
      end
    end
    if @active_column != nil 
      if td.active_column.length == meta_diff.get_width 
        _g11 = 1
        _g3 = meta_diff.get_width
        while(_g11 < _g3) 
          i = _g11
          _g11+=1
          @active_column[i - 1] = 1 if td.active_column[i] >= 0
        end
      end
    end
  end
  false
end
add_rc_numbers(output) click to toggle source
# File lib/lib/coopy/table_diff.rb, line 516
def add_rc_numbers(output)
  admin_w = 1
  if @show_rc_numbers && !@flags.never_show_order 
    admin_w+=1
    target = Array.new
    begin
      _g1 = 0
      _g = output.get_width
      while(_g1 < _g) 
        i = _g1
        _g1+=1
        target.push(i + 1)
      end
    end
    output.insert_or_delete_columns(target,output.get_width + 1)
    begin
      _g11 = 0
      _g2 = output.get_height
      while(_g11 < _g2) 
        i1 = _g11
        _g11+=1
        unit = @row_map[i1]
        if unit == nil 
          output.set_cell(0,i1,"")
          next
        end
        output.set_cell(0,i1,@builder.links(unit,true))
      end
    end
    target = Array.new
    begin
      _g12 = 0
      _g3 = output.get_height
      while(_g12 < _g3) 
        i2 = _g12
        _g12+=1
        target.push(i2 + 1)
      end
    end
    output.insert_or_delete_rows(target,output.get_height + 1)
    begin
      _g13 = 1
      _g4 = output.get_width
      while(_g13 < _g4) 
        i3 = _g13
        _g13+=1
        unit1 = @col_map[i3 - 1]
        if unit1 == nil 
          output.set_cell(i3,0,"")
          next
        end
        output.set_cell(i3,0,@builder.links(unit1,false))
      end
    end
    output.set_cell(0,0,@builder.marker("@:@"))
  end
  admin_w
end
add_schema(output) click to toggle source
# File lib/lib/coopy/table_diff.rb, line 645
def add_schema(output)
  if @have_schema 
    at = output.get_height
    output.resize(@column_units.length + 1,at + 1)
    output.set_cell(0,at,@builder.marker("!"))
    begin
      _g1 = 0
      _g = @column_units.length
      while(_g1 < _g) 
        j = _g1
        _g1+=1
        output.set_cell(j + 1,at,@v.to_datum(@schema[j]))
      end
    end
    @schema_diff_found = true
  end
end
check_meta(t,meta) click to toggle source
# File lib/lib/coopy/table_diff.rb, line 689
def check_meta(t,meta)
  return false if meta == nil
  return meta.get_width == 1 && meta.get_height == 1 if t == nil
  return false if meta.get_width != t.get_width + 1
  return false if meta.get_width == 0 || meta.get_height == 0
  true
end
check_nesting(v,have_ll,ll,have_rr,rr,have_pp,pp,x,y) click to toggle source
# File lib/lib/coopy/table_diff.rb, line 799
def check_nesting(v,have_ll,ll,have_rr,rr,have_pp,pp,x,y)
  all_tables = true
  all_tables = all_tables && v.is_table(ll) if have_ll
  all_tables = all_tables && v.is_table(rr) if have_rr
  all_tables = all_tables && v.is_table(pp) if have_pp
  return [ll,rr,pp] if !all_tables
  ll_table = nil
  rr_table = nil
  pp_table = nil
  ll_table = v.get_table(ll) if have_ll
  rr_table = v.get_table(rr) if have_rr
  pp_table = v.get_table(pp) if have_pp
  compare = false
  comp = ::Coopy::TableComparisonState.new
  comp.a = ll_table
  comp.b = rr_table
  comp.p = pp_table
  comp.compare_flags = @flags
  comp.get_meta
  key = nil
  key = comp.a_meta.get_name if comp.a_meta != nil
  key = comp.b_meta.get_name if key == nil && comp.b_meta != nil
  key = _hx_str(x) + "_" + _hx_str(y) if key == nil
  if @align.comp != nil 
    if @align.comp.children == nil 
      @align.comp.children = {}
      @align.comp.child_order = Array.new
      compare = true
    else 
      compare = !@align.comp.children.include?(key)
    end
  end
  if compare 
    @nesting_present = true
    @align.comp.children[key] = comp
    @align.comp.child_order.push(key)
    ct = ::Coopy::CompareTable.new(comp)
    ct.align
  else 
    comp = @align.comp.children[key]
  end
  ll_out = nil
  rr_out = nil
  pp_out = nil
  if comp.alignment.is_marked_as_identical || have_ll && !have_rr || have_rr && !have_ll 
    ll_out = "[" + _hx_str(key) + "]"
    rr_out = ll_out
    pp_out = ll_out
  else 
    ll_out = "[a." + _hx_str(key) + "]" if ll != nil
    rr_out = "[b." + _hx_str(key) + "]" if rr != nil
    pp_out = "[p." + _hx_str(key) + "]" if pp != nil
  end
  [ll_out,rr_out,pp_out]
end
check_rc_numbers(w,h) click to toggle source
# File lib/lib/coopy/table_diff.rb, line 505
def check_rc_numbers(w,h)
  if !@show_rc_numbers 
    if @flags.always_show_order 
      @show_rc_numbers = true
    elsif @flags.ordered 
      @show_rc_numbers = self.is_reordered(@row_map,h)
      @show_rc_numbers = self.is_reordered(@col_map,w) if !@show_rc_numbers
    end
  end
end
count_active(active) click to toggle source
# File lib/lib/coopy/table_diff.rb, line 243
def count_active(active)
  ct = 0
  showed_dummy = false
  begin
    _g1 = 0
    _g = active.length
    while(_g1 < _g) 
      i = _g1
      _g1+=1
      publish = active[i] > 0
      dummy = active[i] == 3
      next if dummy && showed_dummy
      next if !publish
      showed_dummy = dummy
      ct+=1
    end
  end
  ct
end
elide_columns(output,admin_w) click to toggle source
# File lib/lib/coopy/table_diff.rb, line 575
def elide_columns(output,admin_w)
  if @active_column != nil 
    all_active = true
    begin
      _g1 = 0
      _g = @active_column.length
      while(_g1 < _g) 
        i = _g1
        _g1+=1
        if @active_column[i] == 0 
          all_active = false
          break
        end
      end
    end
    if !all_active 
      fate = Array.new
      begin
        _g2 = 0
        while(_g2 < admin_w) 
          i1 = _g2
          _g2+=1
          fate.push(i1)
        end
      end
      at = admin_w
      ct = 0
      dots = Array.new
      begin
        _g11 = 0
        _g3 = @active_column.length
        while(_g11 < _g3) 
          i2 = _g11
          _g11+=1
          off = @active_column[i2] == 0
          if off 
            ct = ct + 1
          else 
            ct = 0
          end
          if off && ct > 1 
            fate.push(-1)
          else 
            dots.push(at) if off
            fate.push(at)
            at+=1
          end
        end
      end
      output.insert_or_delete_columns(fate,at)
      begin
        _g4 = 0
        while(_g4 < dots.length) 
          d = dots[_g4]
          _g4+=1
          begin
            _g21 = 0
            _g12 = output.get_height
            while(_g21 < _g12) 
              j = _g21
              _g21+=1
              output.set_cell(d,j,@builder.marker("..."))
            end
          end
        end
      end
    end
  end
end
get_meta_table(t) click to toggle source
# File lib/lib/coopy/table_diff.rb, line 697
def get_meta_table(t)
  if t == nil 
    result = ::Coopy::SimpleTable.new(1,1)
    result.set_cell(0,0,"@")
    return result
  end
  meta = t.get_meta
  return nil if meta == nil
  meta.as_table
end
get_separator(t,t2,root) click to toggle source
# File lib/lib/coopy/table_diff.rb, line 75
def get_separator(t,t2,root)
  sep = root
  w = t.get_width
  h = t.get_height
  view = t.get_cell_view
  begin
    _g = 0
    while(_g < h) 
      y = _g
      _g+=1
      begin
        _g1 = 0
        while(_g1 < w) 
          x = _g1
          _g1+=1
          txt = view.to_s(t.get_cell(x,y))
          next if txt == nil
          while((txt.index(sep,nil || 0) || -1) >= 0) 
            sep = "-" + _hx_str(sep)
          end
        end
      end
    end
  end
  if t2 != nil 
    w = t2.get_width
    h = t2.get_height
    begin
      _g2 = 0
      while(_g2 < h) 
        y1 = _g2
        _g2+=1
        begin
          _g11 = 0
          while(_g11 < w) 
            x1 = _g11
            _g11+=1
            txt1 = view.to_s(t2.get_cell(x1,y1))
            next if txt1 == nil
            while((txt1.index(sep,nil || 0) || -1) >= 0) 
              sep = "-" + _hx_str(sep)
            end
          end
        end
      end
    end
  end
  sep
end
hilite_single(output) click to toggle source
# File lib/lib/coopy/table_diff.rb, line 1000
def hilite_single(output)
  return false if !output.is_resizable
  if @builder == nil 
    if @flags.allow_nested_cells 
      @builder = ::Coopy::NestedCellBuilder.new
    else 
      @builder = ::Coopy::FlatCellBuilder.new(@flags)
    end
  end
  output.resize(0,0)
  output.clear
  self.reset
  self.setup_tables
  self.setup_columns
  self.setup_moves
  self.scan_activity
  self.scan_schema
  self.add_schema(output)
  self.add_header(output)
  self.add_meta(output)
  outer_reps_needed = nil
  if @flags.show_unchanged && @flags.show_unchanged_columns 
    outer_reps_needed = 1
  else 
    outer_reps_needed = 2
  end
  output_height = output.get_height
  output_height_init = output.get_height
  begin
    _g = 0
    while(_g < outer_reps_needed) 
      out = _g
      _g+=1
      if out == 1 
        self.refine_activity
        rows = self.count_active(@active_row) + output_height_init
        rows-=1 if @top_line_done
        output_height = output_height_init
        output.resize(@column_units.length + 1,rows) if rows > output.get_height
      end
      showed_dummy = false
      l = -1
      r = -1
      begin
        _g2 = 0
        _g1 = @row_units.length
        while(_g2 < _g1) 
          i = _g2
          _g2+=1
          unit = @row_units[i]
          reordered = false
          if @flags.ordered 
            reordered = true if @row_moves.include?(i)
            @show_rc_numbers = true if reordered
          end
          next if unit.r < 0 && unit.l < 0
          next if unit.r == 0 && unit.lp <= 0 && @top_line_done
          @publish = @flags.show_unchanged
          dummy = false
          if out == 1 
            value = @active_row[i]
            @publish = value != nil && value > 0
            dummy = value != nil && value == 3
            next if dummy && showed_dummy
            next if !@publish
          end
          showed_dummy = false if !dummy
          at = output_height
          if @publish 
            output_height+=1
            output.resize(@column_units.length + 1,output_height) if output.get_height < output_height
          end
          if dummy 
            begin
              _g4 = 0
              _g3 = @column_units.length + 1
              while(_g4 < _g3) 
                j = _g4
                _g4+=1
                output.set_cell(j,at,@v.to_datum("..."))
              end
            end
            showed_dummy = true
            next
          end
          @have_addition = false
          skip = false
          @act = ""
          if reordered 
            @act = ":"
            @row_reorders+=1 if out == 0
          end
          if unit.p < 0 && unit.l < 0 && unit.r >= 0 
            skip = true if !@allow_insert
            @act = "+++"
            @row_inserts+=1 if out == 0 && !skip
          end
          if (unit.p >= 0 || !@has_parent) && unit.l >= 0 && unit.r < 0 
            skip = true if !@allow_delete
            @act = "---"
            @row_deletes+=1 if out == 0 && !skip
          end
          if skip 
            if !@publish 
              @active_row[i] = -3 if @active_row != nil
            end
            next
          end
          self.scan_row(unit,output,at,i,out)
        end
      end
    end
  end
  self.check_rc_numbers(output.get_width,output.get_height)
  admin_w = self.add_rc_numbers(output)
  self.elide_columns(output,admin_w) if !@preserve_columns
  true
end
is_equal(v,aa,bb) click to toggle source
# File lib/lib/coopy/table_diff.rb, line 794
def is_equal(v,aa,bb)
  return self.normalize_string(v,aa) == self.normalize_string(v,bb) if @flags.ignore_whitespace || @flags.ignore_case
  v.equals(aa,bb)
end
is_reordered(m,ct) click to toggle source
# File lib/lib/coopy/table_diff.rb, line 144
def is_reordered(m,ct)
  reordered = false
  l = -1
  r = -1
  begin
    _g = 0
    while(_g < ct) 
      i = _g
      _g+=1
      unit = m[i]
      next if unit == nil
      if unit.l >= 0 
        if unit.l < l 
          reordered = true
          break
        end
        l = unit.l
      end
      if unit.r >= 0 
        if unit.r < r 
          reordered = true
          break
        end
        r = unit.r
      end
    end
  end
  reordered
end
normalize_string(v,str) click to toggle source
# File lib/lib/coopy/table_diff.rb, line 785
def normalize_string(v,str)
  return str if str == nil
  return str if !(@flags.ignore_whitespace || @flags.ignore_case)
  txt = v.to_s(str)
  txt = txt.strip if @flags.ignore_whitespace
  txt = txt.downcase if @flags.ignore_case
  txt
end
quote_for_diff(v,d) click to toggle source
# File lib/lib/coopy/table_diff.rb, line 125
def quote_for_diff(v,d)
  _nil = "NULL"
  return _nil if v.equals(d,nil)
  str = v.to_s(d)
  score = 0
  begin
    _g1 = 0
    _g = str.length
    while(_g1 < _g) 
      i = _g1
      _g1+=1
      break if (str[score].ord rescue nil) != 95
      score+=1
    end
  end
  str = "_" + _hx_str(str) if str[score..-1] == _nil
  str
end
refine_activity() click to toggle source
# File lib/lib/coopy/table_diff.rb, line 771
def refine_activity 
  self.spread_context(@row_units,@flags.unchanged_context,@active_row)
  self.spread_context(@column_units,@flags.unchanged_column_context,@active_column)
  if @active_column != nil 
    _g1 = 0
    _g = @column_units.length
    while(_g1 < _g) 
      i = _g1
      _g1+=1
      @active_column[i] = 0 if @active_column[i] == 3
    end
  end
end
reset() click to toggle source
# File lib/lib/coopy/table_diff.rb, line 263
def reset 
  @has_parent = false
  @rp_header = @ra_header = @rb_header = 0
  @is_index_p = {}
  @is_index_a = {}
  @is_index_b = {}
  @row_map = {}
  @col_map = {}
  @show_rc_numbers = false
  @row_moves = nil
  @col_moves = nil
  @allow_insert = @allow_delete = @allow_update = true
  @sep = ""
  @conflict_sep = ""
  @top_line_done = false
  @diff_found = false
  @schema_diff_found = false
  @row_deletes = 0
  @row_inserts = 0
  @row_updates = 0
  @row_reorders = 0
  @col_deletes = 0
  @col_inserts = 0
  @col_updates = 0
  @col_renames = 0
  @col_reorders = 0
  @column_units_updated = {}
end
scan_activity() click to toggle source
# File lib/lib/coopy/table_diff.rb, line 355
def scan_activity 
  @active_row = Array.new
  @active_column = nil
  if !@flags.show_unchanged 
    _g1 = 0
    _g = @row_units.length
    while(_g1 < _g) 
      i = _g1
      _g1+=1
      @active_row[@row_units.length - 1 - i] = 0
    end
  end
  if !@flags.show_unchanged_columns 
    @active_column = Array.new
    begin
      _g11 = 0
      _g2 = @column_units.length
      while(_g11 < _g2) 
        i1 = _g11
        _g11+=1
        v = 0
        unit = @column_units[i1]
        v = 1 if unit.l >= 0 && @is_index_a[unit.l]
        v = 1 if unit.r >= 0 && @is_index_b[unit.r]
        v = 1 if unit.p >= 0 && @is_index_p[unit.p]
        @active_column[i1] = v
      end
    end
  end
end
scan_row(unit,output,at,i,out) click to toggle source
# File lib/lib/coopy/table_diff.rb, line 855
def scan_row(unit,output,at,i,out)
  row_update = false
  begin
    _g1 = 0
    _g = @column_units.length
    while(_g1 < _g) 
      j = _g1
      _g1+=1
      cunit = @column_units[j]
      pp = nil
      ll = nil
      rr = nil
      dd = nil
      dd_to = nil
      have_dd_to = false
      dd_to_alt = nil
      have_dd_to_alt = false
      have_pp = false
      have_ll = false
      have_rr = false
      if cunit.p >= 0 && unit.p >= 0 
        pp = @p.get_cell(cunit.p,unit.p)
        have_pp = true
      end
      if cunit.l >= 0 && unit.l >= 0 
        ll = @a.get_cell(cunit.l,unit.l)
        have_ll = true
      end
      if cunit.r >= 0 && unit.r >= 0 
        rr = @b.get_cell(cunit.r,unit.r)
        have_rr = true
        if (((have_pp) ? cunit.p : cunit.l)) < 0 
          if rr != nil 
            if @v.to_s(rr) != "" 
              @have_addition = true if @flags.allow_update
            end
          end
        end
      end
      if @nested 
        ndiff = self.check_nesting(@v,have_ll,ll,have_rr,rr,have_pp,pp,i,j)
        ll = ndiff[0]
        rr = ndiff[1]
        pp = ndiff[2]
      end
      if have_pp 
        if !have_rr 
          dd = pp
        elsif self.is_equal(@v,pp,rr) 
          dd = ll
        else 
          dd = pp
          dd_to = rr
          have_dd_to = true
          if !self.is_equal(@v,pp,ll) 
            if !self.is_equal(@v,pp,rr) 
              dd_to_alt = ll
              have_dd_to_alt = true
            end
          end
        end
      elsif have_ll 
        if !have_rr 
          dd = ll
        elsif self.is_equal(@v,ll,rr) 
          dd = ll
        else 
          dd = ll
          dd_to = rr
          have_dd_to = true
        end
      else 
        dd = rr
      end
      cell = dd
      if have_dd_to && @allow_update 
        if !row_update 
          @row_updates+=1 if out == 0
          row_update = true
        end
        @active_column[j] = 1 if @active_column != nil
        if @sep == "" 
          if @builder.need_separator 
            @sep = self.get_separator(@a,@b,"->")
            @builder.set_separator(@sep)
          else 
            @sep = "->"
          end
        end
        is_conflict = false
        if have_dd_to_alt 
          is_conflict = true if !self.is_equal(@v,dd_to,dd_to_alt)
        end
        if !is_conflict 
          cell = @builder.update(dd,dd_to)
          @act = @sep if @sep.length > @act.length
        else 
          if @conflict_sep == "" 
            if @builder.need_separator 
              @conflict_sep = _hx_str(self.get_separator(@p,@a,"!")) + _hx_str(@sep)
              @builder.set_conflict_separator(@conflict_sep)
            else 
              @conflict_sep = "!->"
            end
          end
          cell = @builder.conflict(dd,dd_to_alt,dd_to)
          @act = @conflict_sep
        end
        if !@column_units_updated.include?(j) 
          @column_units_updated[j] = true
          @col_updates+=1
        end
      end
      @act = "+" if @act == "" && @have_addition
      if @act == "+++" 
        if have_rr 
          @active_column[j] = 1 if @active_column != nil
        end
      end
      if @publish 
        output.set_cell(j + 1,at,cell) if @active_column == nil || @active_column[j] > 0
      end
    end
  end
  if @publish 
    output.set_cell(0,at,@builder.marker(@act))
    @row_map[at] = unit
  end
  if @act != "" 
    @diff_found = true
    if !@publish 
      @active_row[i] = 1 if @active_row != nil
    end
  end
end
scan_schema() click to toggle source
# File lib/lib/coopy/table_diff.rb, line 446
def scan_schema 
  @schema = Array.new
  @have_schema = false
  begin
    _g1 = 0
    _g = @column_units.length
    while(_g1 < _g) 
      j = _g1
      _g1+=1
      cunit = @column_units[j]
      reordered = false
      if @flags.ordered 
        reordered = true if @col_moves.include?(j)
        @show_rc_numbers = true if reordered
      end
      act = ""
      if cunit.r >= 0 && cunit.lp == -1 
        @have_schema = true
        act = "+++"
        if @active_column != nil 
          @active_column[j] = 1 if @allow_update
        end
        @col_inserts+=1 if @allow_update
      end
      if cunit.r < 0 && cunit.lp >= 0 
        @have_schema = true
        act = "---"
        if @active_column != nil 
          @active_column[j] = 1 if @allow_update
        end
        @col_deletes+=1 if @allow_update
      end
      if cunit.r >= 0 && cunit.lp >= 0 
        if @p.get_height >= @rp_header && @b.get_height >= @rb_header 
          pp = @p.get_cell(cunit.lp,@rp_header)
          bb = @b.get_cell(cunit.r,@rb_header)
          if !self.is_equal(@v,pp,bb) 
            @have_schema = true
            act = "("
            act += @v.to_s(pp)
            act += ")"
            if @active_column != nil 
              @active_column[j] = 1
              @col_renames+=1
            end
          end
        end
      end
      if reordered 
        act = ":" + _hx_str(act)
        @have_schema = true
        @active_column = nil if @active_column != nil
        @col_reorders+=1
      end
      @schema.push(act)
    end
  end
end
set_ignore(ignore,idx_ignore,tab,r_header) click to toggle source
# File lib/lib/coopy/table_diff.rb, line 228
def set_ignore(ignore,idx_ignore,tab,r_header)
  v = tab.get_cell_view
  if tab.get_height >= r_header 
    _g1 = 0
    _g = tab.get_width
    while(_g1 < _g) 
      i = _g1
      _g1+=1
      name = v.to_s(tab.get_cell(i,r_header))
      next if !ignore.include?(name)
      idx_ignore[i] = true
    end
  end
end
setup_columns() click to toggle source
# File lib/lib/coopy/table_diff.rb, line 386
def setup_columns 
  column_order = @align.meta.to_order
  @column_units = column_order.get_list
  ignore = @flags.get_ignored_columns
  if ignore != nil 
    p_ignore = {}
    a_ignore = {}
    b_ignore = {}
    self.set_ignore(ignore,p_ignore,@p,@rp_header)
    self.set_ignore(ignore,a_ignore,@a,@ra_header)
    self.set_ignore(ignore,b_ignore,@b,@rb_header)
    ncolumn_units = Array.new
    begin
      _g1 = 0
      _g = @column_units.length
      while(_g1 < _g) 
        j = _g1
        _g1+=1
        cunit = @column_units[j]
        next if p_ignore.include?(cunit.p) || a_ignore.include?(cunit.l) || b_ignore.include?(cunit.r)
        ncolumn_units.push(cunit)
      end
    end
    @column_units = ncolumn_units
  end
end
setup_moves() click to toggle source
# File lib/lib/coopy/table_diff.rb, line 413
def setup_moves 
  if @flags.ordered 
    @row_moves = {}
    moves = ::Coopy::Mover.move_units(@row_units)
    begin
      _g1 = 0
      _g = moves.length
      while(_g1 < _g) 
        i = _g1
        _g1+=1
        begin
          @row_moves[moves[i]] = i
          i
        end
      end
    end
    @col_moves = {}
    moves = ::Coopy::Mover.move_units(@column_units)
    begin
      _g11 = 0
      _g2 = moves.length
      while(_g11 < _g2) 
        i1 = _g11
        _g11+=1
        begin
          @col_moves[moves[i1]] = i1
          i1
        end
      end
    end
  end
end
setup_tables() click to toggle source
# File lib/lib/coopy/table_diff.rb, line 292
def setup_tables 
  @order = @align.to_order
  @row_units = @order.get_list
  @has_parent = @align.reference != nil
  if @has_parent 
    @p = @align.get_source
    @a = @align.reference.get_target
    @b = @align.get_target
    @rp_header = @align.reference.meta.get_source_header
    @ra_header = @align.reference.meta.get_target_header
    @rb_header = @align.meta.get_target_header
    if @align.get_index_columns != nil 
      _g = 0
      _g1 = @align.get_index_columns
      while(_g < _g1.length) 
        p2b = _g1[_g]
        _g+=1
        @is_index_p[p2b.l] = true if p2b.l >= 0
        @is_index_b[p2b.r] = true if p2b.r >= 0
      end
    end
    if @align.reference.get_index_columns != nil 
      _g2 = 0
      _g11 = @align.reference.get_index_columns
      while(_g2 < _g11.length) 
        p2a = _g11[_g2]
        _g2+=1
        @is_index_p[p2a.l] = true if p2a.l >= 0
        @is_index_a[p2a.r] = true if p2a.r >= 0
      end
    end
  else 
    @a = @align.get_source
    @b = @align.get_target
    @p = @a
    @ra_header = @align.meta.get_source_header
    @rp_header = @ra_header
    @rb_header = @align.meta.get_target_header
    if @align.get_index_columns != nil 
      _g3 = 0
      _g12 = @align.get_index_columns
      while(_g3 < _g12.length) 
        a2b = _g12[_g3]
        _g3+=1
        @is_index_a[a2b.l] = true if a2b.l >= 0
        @is_index_b[a2b.r] = true if a2b.r >= 0
      end
    end
  end
  @allow_insert = @flags.allow_insert
  @allow_delete = @flags.allow_delete
  @allow_update = @flags.allow_update
  common = @a
  common = @b if common == nil
  common = @p if common == nil
  @v = common.get_cell_view
  @builder.set_view(@v)
  @nested = false
  meta = common.get_meta
  @nested = meta.is_nested if meta != nil
  @nesting_present = false
end
spread_context(units,del,active) click to toggle source
# File lib/lib/coopy/table_diff.rb, line 174
def spread_context(units,del,active)
  if del > 0 && active != nil 
    mark = -del - 1
    skips = 0
    begin
      _g1 = 0
      _g = units.length
      while(_g1 < _g) 
        i = _g1
        _g1+=1
        if active[i] == -3 
          skips+=1
          next
        end
        if active[i] == 0 || active[i] == 3 
          if i - mark <= del + skips 
            active[i] = 2
          elsif i - mark == del + 1 + skips 
            active[i] = 3
          end
        elsif active[i] == 1 
          mark = i
          skips = 0
        end
      end
    end
    mark = units.length + del + 1
    skips = 0
    begin
      _g11 = 0
      _g2 = units.length
      while(_g11 < _g2) 
        j = _g11
        _g11+=1
        i1 = units.length - 1 - j
        if active[i1] == -3 
          skips+=1
          next
        end
        if active[i1] == 0 || active[i1] == 3 
          if mark - i1 <= del + skips 
            active[i1] = 2
          elsif mark - i1 == del + 1 + skips 
            active[i1] = 3
          end
        elsif active[i1] == 1 
          mark = i1
          skips = 0
        end
      end
    end
  end
end