Class: Twb::JoinTree

Inherits:
Object
  • Object
show all
Defined in:
lib/twb/datasource.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(datasource) ⇒ JoinTree

Returns a new instance of JoinTree.



430
431
432
433
434
435
# File 'lib/twb/datasource.rb', line 430

def initialize  datasource
  @datasource = datasource
  @root       = nil
  @maxdepth   = 0
  @tables     = {}
end

Instance Attribute Details

#datasourceObject (readonly)

Returns the value of attribute datasource.



428
429
430
# File 'lib/twb/datasource.rb', line 428

def datasource
  @datasource
end

#maxdepthObject (readonly)

Returns the value of attribute maxdepth.



428
429
430
# File 'lib/twb/datasource.rb', line 428

def maxdepth
  @maxdepth
end

#rootObject (readonly)

Returns the value of attribute root.



428
429
430
# File 'lib/twb/datasource.rb', line 428

def root
  @root
end

#tablesObject (readonly)

Returns the value of attribute tables.



428
429
430
# File 'lib/twb/datasource.rb', line 428

def tables
  @tables
end

Instance Method Details

#add(host, dest) ⇒ Object



437
438
439
440
441
442
443
444
445
446
447
448
449
# File 'lib/twb/datasource.rb', line 437

def add host, dest
  # puts "\nJT add() host: #{host}"
  # puts "           dest: #{dest}"
  from = @tables[host.name].nil? ? host : @tables[host.name]
  to   = @tables[dest.name].nil? ? dest : @tables[dest.name]
  from.addChild(to)
  @tables[from.name] = from
  @tables[to.name]   = to
  if @root.nil?  || @root.name.eql?(to.name)
    @root = from
  end
  setDepth(@root,1)
end

#disp(table) ⇒ Object



466
467
468
469
# File 'lib/twb/datasource.rb', line 466

def disp table
  puts "%s %s %s  (%d)" % [' ' * table.depth, '-' * table.depth, table.name, table.depth]
  table.children.each { |n,c| disp c}
end

#iterateObject



471
472
473
# File 'lib/twb/datasource.rb', line 471

def iterate
  disp @root
end

#setDepth(table, depth) ⇒ Object



455
456
457
458
459
460
# File 'lib/twb/datasource.rb', line 455

def setDepth table, depth
  # puts "-- setDepth(#{table.class}[#{table.name}] \t, #{depth})"
  @tables[table.name].depth = depth
  childrenDepth = depth+1
  table.children.each { |n,c| setDepth(c,childrenDepth)}
end

#table(tableName) ⇒ Object



451
452
453
# File 'lib/twb/datasource.rb', line 451

def table tableName
  @tables[tableName]
end

#tableDepth(tableName) ⇒ Object



462
463
464
# File 'lib/twb/datasource.rb', line 462

def tableDepth tableName
  @tables[tableName].nil? ? 0 : @tables[tableName].depth
end

#to_sObject



475
476
477
478
479
480
481
# File 'lib/twb/datasource.rb', line 475

def to_s
  str = "root: #{@root}\ntables"
  @tables.each do |t| 
    str << " tbl:: #{t}"
  end
  return str
end