Class: ExpectationTreeNode
- Inherits:
-
Object
- Object
- ExpectationTreeNode
- Includes:
- Enumerable
- Defined in:
- lib/dbexpect/expectation_tree_node.rb
Overview
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/>.
Defined Under Namespace
Classes: EmptyTreeNode
Instance Method Summary collapse
- #add(expectations) ⇒ Object
- #create_child(desc) ⇒ Object
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(desc, children = [], expectations = []) ⇒ ExpectationTreeNode
constructor
A new instance of ExpectationTreeNode.
- #select(&block) ⇒ Object
- #traverse(depth = 0, &block) ⇒ Object
Constructor Details
#initialize(desc, children = [], expectations = []) ⇒ ExpectationTreeNode
Returns a new instance of ExpectationTreeNode.
20 21 22 23 24 |
# File 'lib/dbexpect/expectation_tree_node.rb', line 20 def initialize(desc,children = [], expectations = []) @description = desc @children = children @expectations = expectations end |
Instance Method Details
#add(expectations) ⇒ Object
47 48 49 |
# File 'lib/dbexpect/expectation_tree_node.rb', line 47 def add(expectations) @expectations += expectations end |
#create_child(desc) ⇒ Object
42 43 44 45 |
# File 'lib/dbexpect/expectation_tree_node.rb', line 42 def create_child(desc) @children << ExpectationTreeNode.new(desc) @children.last end |
#each(&block) ⇒ Object
26 27 28 29 |
# File 'lib/dbexpect/expectation_tree_node.rb', line 26 def each(&block) @expectations.map(&block) @children.each {|c| c.each(&block) } end |
#empty? ⇒ Boolean
51 52 53 |
# File 'lib/dbexpect/expectation_tree_node.rb', line 51 def empty? @expectations.empty? && @children.all?(&:empty?) end |
#select(&block) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# 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) ⇒ Object
55 56 57 58 |
# 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 |