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
545 546 547 548 549 550 |
# File 'lib/twb/datasource.rb', line 545 def initialize datasource @datasource = datasource @root = nil @maxdepth = 0 @tables = {} end |
Instance Attribute Details
#datasource ⇒ Object (readonly)
Returns the value of attribute datasource.
543 544 545 |
# File 'lib/twb/datasource.rb', line 543 def datasource @datasource end |
#maxdepth ⇒ Object (readonly)
Returns the value of attribute maxdepth.
543 544 545 |
# File 'lib/twb/datasource.rb', line 543 def maxdepth @maxdepth end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
543 544 545 |
# File 'lib/twb/datasource.rb', line 543 def root @root end |
#tables ⇒ Object (readonly)
Returns the value of attribute tables.
543 544 545 |
# File 'lib/twb/datasource.rb', line 543 def tables @tables end |
Instance Method Details
#add(host, dest) ⇒ Object
552 553 554 555 556 557 558 559 560 561 562 563 564 |
# File 'lib/twb/datasource.rb', line 552 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
581 582 583 584 |
# File 'lib/twb/datasource.rb', line 581 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
586 587 588 |
# File 'lib/twb/datasource.rb', line 586 def iterate disp @root end |
#setDepth(table, depth) ⇒ Object
570 571 572 573 574 575 |
# File 'lib/twb/datasource.rb', line 570 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
566 567 568 |
# File 'lib/twb/datasource.rb', line 566 def table tableName @tables[tableName] end |
#tableDepth(tableName) ⇒ Object
577 578 579 |
# File 'lib/twb/datasource.rb', line 577 def tableDepth tableName @tables[tableName].nil? ? 0 : @tables[tableName].depth end |
#to_s ⇒ Object
590 591 592 593 594 595 596 |
# File 'lib/twb/datasource.rb', line 590 def to_s str = "root: #{@root}\ntables" @tables.each do |t| str << " tbl:: #{t}" end return str end |