class ExpectationTreeNode

Copyright 2012 C3 Business Solutions

This file is part of dbexpect.

dbexpect is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

dbexpect is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with dbexpect.  If not, see <http://www.gnu.org/licenses/>.

Public Class Methods

new(desc,children = [], expectations = []) click to toggle source
# File lib/dbexpect/expectation_tree_node.rb, line 20
def initialize(desc,children = [], expectations = [])
  @description = desc
  @children = children
  @expectations = expectations
end

Public Instance Methods

add(expectations) click to toggle source
# File lib/dbexpect/expectation_tree_node.rb, line 47
def add(expectations)
  @expectations += expectations
end
create_child(desc) click to toggle source
# File lib/dbexpect/expectation_tree_node.rb, line 42
def create_child(desc)
  @children << ExpectationTreeNode.new(desc)
  @children.last
end
each(&block) click to toggle source
# File lib/dbexpect/expectation_tree_node.rb, line 26
def each(&block)
  @expectations.map(&block)
  @children.each {|c| c.each(&block) }
end
empty?() click to toggle source
# File lib/dbexpect/expectation_tree_node.rb, line 51
def empty?
  @expectations.empty? && @children.all?(&:empty?)
end
select(&block) click to toggle source
# File lib/dbexpect/expectation_tree_node.rb, line 31
def select(&block)
  matching_children = @children.collect {|c| c.select(&block) }.
    reject {|node| node === EmptyTreeNode }

  matching_expectations = @expectations.select(&block)

  return EmptyTreeNode.new if matching_children.empty? && matching_expectations.empty?

  ExpectationTreeNode.new(@description,matching_children,matching_expectations)
end
traverse(depth = 0, &block) click to toggle source
# File lib/dbexpect/expectation_tree_node.rb, line 55
def traverse(depth = 0, &block)
  block.call(depth,@description,@expectations)
  @children.map {|c| c.traverse(depth + 1, &block) }
end