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.



648
649
650
651
652
653
# File 'lib/twb/datasource.rb', line 648

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

Instance Attribute Details

#datasourceObject (readonly)

Returns the value of attribute datasource.



646
647
648
# File 'lib/twb/datasource.rb', line 646

def datasource
  @datasource
end

#maxdepthObject (readonly)

Returns the value of attribute maxdepth.



646
647
648
# File 'lib/twb/datasource.rb', line 646

def maxdepth
  @maxdepth
end

#rootObject (readonly)

Returns the value of attribute root.



646
647
648
# File 'lib/twb/datasource.rb', line 646

def root
  @root
end

#tablesObject (readonly)

Returns the value of attribute tables.



646
647
648
# File 'lib/twb/datasource.rb', line 646

def tables
  @tables
end

Instance Method Details

#add(host, dest) ⇒ Object



655
656
657
658
659
660
661
662
663
664
665
666
667
# File 'lib/twb/datasource.rb', line 655

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



684
685
686
687
# File 'lib/twb/datasource.rb', line 684

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



689
690
691
# File 'lib/twb/datasource.rb', line 689

def iterate
  disp @root
end

#setDepth(table, depth) ⇒ Object



673
674
675
676
677
678
# File 'lib/twb/datasource.rb', line 673

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



669
670
671
# File 'lib/twb/datasource.rb', line 669

def table tableName
  @tables[tableName]
end

#tableDepth(tableName) ⇒ Object



680
681
682
# File 'lib/twb/datasource.rb', line 680

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

#to_sObject



693
694
695
696
697
698
699
# File 'lib/twb/datasource.rb', line 693

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