class Coopy::SimpleMeta
Attributes
has_properties[RW]
keys[RW]
may_be_nested[RW]
metadata[RW]
name2col[RW]
name2row[RW]
row_active[RW]
row_change_cache[RW]
t[RW]
Public Class Methods
new(t,has_properties = true,may_be_nested = false)
click to toggle source
# File lib/lib/coopy/simple_meta.rb, line 7 def initialize(t,has_properties = true,may_be_nested = false) @t = t self.row_change self.col_change @has_properties = has_properties @may_be_nested = may_be_nested @metadata = nil @keys = nil @row_active = false @row_change_cache = nil end
Public Instance Methods
add_meta_data(column,property,val)
click to toggle source
# File lib/lib/coopy/simple_meta.rb, line 182 def add_meta_data(column,property,val) if @metadata == nil @metadata = {} @keys = {} end if !@metadata.include?(column) value = {} @metadata[column] = value end props = @metadata[column] begin value1 = val begin value2 = value1 props[property] = value2 end end @keys[property] = true end
alter_columns(columns)
click to toggle source
# File lib/lib/coopy/simple_meta.rb, line 92 def alter_columns(columns) target = {} wfate = 0 if @has_properties target["@"] = wfate wfate+=1 end begin _g1 = 0 _g = columns.length while(_g1 < _g) i = _g1 _g1+=1 col = columns[i] target[col.prev_name] = wfate if col.prev_name != nil wfate+=1 if col.name != nil end end fate = Array.new begin _g11 = 0 _g2 = @t.get_width while(_g11 < _g2) i1 = _g11 _g11+=1 targeti = -1 name = @t.get_cell(i1,0) targeti = target[name] if target.include?(name) fate.push(targeti) end end @t.insert_or_delete_columns(fate,wfate) start = nil if @has_properties start = 1 else start = 0 end at = start begin _g12 = 0 _g3 = columns.length while(_g12 < _g3) i2 = _g12 _g12+=1 col1 = columns[i2] if col1.name != nil @t.set_cell(at,0,col1.name) if col1.name != col1.prev_name end at+=1 if col1.name != nil end end return true if !@has_properties self.col_change at = start begin _g13 = 0 _g4 = columns.length while(_g13 < _g4) i3 = _g13 _g13+=1 col2 = columns[i3] if col2.name != nil _g21 = 0 _g31 = col2.props while(_g21 < _g31.length) prop = _g31[_g21] _g21+=1 self.set_cell(col2.name,prop.name,prop.val) end end at+=1 if col2.name != nil end end true end
apply_flags(flags)
click to toggle source
# File lib/lib/coopy/simple_meta.rb, line 291 def apply_flags(flags) false end
as_table()
click to toggle source
# File lib/lib/coopy/simple_meta.rb, line 202 def as_table return @t if @has_properties && @metadata == nil return nil if @metadata == nil w = @t.get_width props = Array.new _it = ::Rb::RubyIterator.new(@keys.keys) while(_it.has_next) do k = _it._next props.push(k) end props.sort!{|a,b| Reflect.compare(a,b)} mt = ::Coopy::SimpleTable.new(w + 1,props.length + 1) mt.set_cell(0,0,"@") begin _g = 0 while(_g < w) x = _g _g+=1 name = @t.get_cell(x,0) mt.set_cell(1 + x,0,name) next if !@metadata.include?(name) vals = @metadata[name] begin _g2 = 0 _g1 = props.length while(_g2 < _g1) i = _g2 _g2+=1 mt.set_cell(1 + x,i + 1,vals[props[i]]) if vals.include?(props[i]) end end end end begin _g11 = 0 _g3 = props.length while(_g11 < _g3) y = _g11 _g11+=1 mt.set_cell(0,y + 1,props[y]) end end mt end
change_row(rc)
click to toggle source
# File lib/lib/coopy/simple_meta.rb, line 286 def change_row(rc) @row_change_cache.push(rc) false end
clone_meta(table = nil)
click to toggle source
# File lib/lib/coopy/simple_meta.rb, line 247 def clone_meta(table = nil) result = ::Coopy::SimpleMeta.new(table) if @metadata != nil result.keys = {} _it = ::Rb::RubyIterator.new(@keys.keys) while(_it.has_next) do k = _it._next result.keys[k] = true end result.metadata = {} _it2 = ::Rb::RubyIterator.new(@metadata.keys) while(_it2.has_next) do k1 = _it2._next next if !@metadata.include?(k1) vals = @metadata[k1] nvals = {} _it3 = ::Rb::RubyIterator.new(vals.keys) while(_it3.has_next) do p = _it3._next value = vals[p] begin value1 = value nvals[p] = value1 end end result.metadata[k1] = nvals end end result end
get_name()
click to toggle source
# File lib/lib/coopy/simple_meta.rb, line 307 def get_name nil end
get_row_stream()
click to toggle source
# File lib/lib/coopy/simple_meta.rb, line 295 def get_row_stream ::Coopy::TableStream.new(@t) end
is_nested()
click to toggle source
# File lib/lib/coopy/simple_meta.rb, line 299 def is_nested @may_be_nested end
is_sql()
click to toggle source
# File lib/lib/coopy/simple_meta.rb, line 303 def is_sql false end
store_row_changes(changes)
click to toggle source
# File lib/lib/coopy/simple_meta.rb, line 33 def store_row_changes(changes) @row_change_cache = changes @row_active = true end
use_for_column_changes()
click to toggle source
# File lib/lib/coopy/simple_meta.rb, line 278 def use_for_column_changes true end
use_for_row_changes()
click to toggle source
# File lib/lib/coopy/simple_meta.rb, line 282 def use_for_row_changes @row_active end
Protected Instance Methods
col(key)
click to toggle source
# File lib/lib/coopy/simple_meta.rb, line 48 def col(key) return -1 if @t.get_height < 1 if @name2col == nil @name2col = {} w = @t.get_width begin _g = 0 while(_g < w) c = _g _g+=1 begin key1 = @t.get_cell(c,0) @name2col[key1] = c end end end end return -1 if !@name2col.include?(key) @name2col[key] end
col_change()
click to toggle source
# File lib/lib/coopy/simple_meta.rb, line 44 def col_change @name2col = nil end
row(key)
click to toggle source
# File lib/lib/coopy/simple_meta.rb, line 69 def row(key) return -1 if @t.get_width < 1 if @name2row == nil @name2row = {} h = @t.get_height begin _g = 1 while(_g < h) r = _g _g+=1 begin key1 = @t.get_cell(0,r) @name2row[key1] = r end end end end return -1 if !@name2row.include?(key) @name2row[key] end
row_change()
click to toggle source
# File lib/lib/coopy/simple_meta.rb, line 40 def row_change @name2row = nil end
set_cell(c,r,val)
click to toggle source
# File lib/lib/coopy/simple_meta.rb, line 171 def set_cell(c,r,val) ri = self.row(r) return false if ri == -1 ci = self.col(c) return false if ci == -1 @t.set_cell(ci,ri,val) true end