Class: Twb::JoinTree
- Inherits:
-
Object
- Object
- Twb::JoinTree
- Defined in:
- lib/twb/datasource.rb
Instance Attribute Summary collapse
-
#datasource ⇒ Object
readonly
Returns the value of attribute datasource.
-
#maxdepth ⇒ Object
readonly
Returns the value of attribute maxdepth.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
-
#tables ⇒ Object
readonly
Returns the value of attribute tables.
Instance Method Summary collapse
- #add(host, dest) ⇒ Object
- #disp(table) ⇒ Object
-
#initialize(datasource) ⇒ JoinTree
constructor
A new instance of JoinTree.
- #iterate ⇒ Object
- #setDepth(table, depth) ⇒ Object
- #table(tableName) ⇒ Object
- #tableDepth(tableName) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(datasource) ⇒ JoinTree
Returns a new instance of JoinTree.
630 631 632 633 634 635 |
# File 'lib/twb/datasource.rb', line 630 def initialize datasource @datasource = datasource @root = nil @maxdepth = 0 @tables = {} end |
Instance Attribute Details
#datasource ⇒ Object (readonly)
Returns the value of attribute datasource.
628 629 630 |
# File 'lib/twb/datasource.rb', line 628 def datasource @datasource end |
#maxdepth ⇒ Object (readonly)
Returns the value of attribute maxdepth.
628 629 630 |
# File 'lib/twb/datasource.rb', line 628 def maxdepth @maxdepth end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
628 629 630 |
# File 'lib/twb/datasource.rb', line 628 def root @root end |
#tables ⇒ Object (readonly)
Returns the value of attribute tables.
628 629 630 |
# File 'lib/twb/datasource.rb', line 628 def tables @tables end |
Instance Method Details
#add(host, dest) ⇒ Object
637 638 639 640 641 642 643 644 645 646 647 648 649 |
# File 'lib/twb/datasource.rb', line 637 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
666 667 668 669 |
# File 'lib/twb/datasource.rb', line 666 def disp table # puts "%s %s %s (%d)" % [' ' * table.depth, '-' * table.depth, table.name, table.depth] table.children.each { |n,c| disp c} end |
#iterate ⇒ Object
671 672 673 |
# File 'lib/twb/datasource.rb', line 671 def iterate disp @root end |
#setDepth(table, depth) ⇒ Object
655 656 657 658 659 660 |
# File 'lib/twb/datasource.rb', line 655 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
651 652 653 |
# File 'lib/twb/datasource.rb', line 651 def table tableName @tables[tableName] end |
#tableDepth(tableName) ⇒ Object
662 663 664 |
# File 'lib/twb/datasource.rb', line 662 def tableDepth tableName @tables[tableName].nil? ? 0 : @tables[tableName].depth end |
#to_s ⇒ Object
675 676 677 678 679 680 681 |
# File 'lib/twb/datasource.rb', line 675 def to_s str = "root: #{@root}\ntables" @tables.each do |t| str << " tbl:: #{t}" end return str end |