Class: JasmineParser::NodeCollector

Inherits:
Object
  • Object
show all
Defined in:
lib/jasmine-parser/node_collector.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nodes, type_wanted, refine_search = {}) ⇒ NodeCollector

Returns a new instance of NodeCollector.



43
44
45
46
47
# File 'lib/jasmine-parser/node_collector.rb', line 43

def initialize(nodes, type_wanted, refine_search = {})
  @nodes = []

  drill_down(nodes, type_wanted, @nodes, refine_search)
end

Instance Attribute Details

#nodesObject (readonly)

Returns the value of attribute nodes.



41
42
43
# File 'lib/jasmine-parser/node_collector.rb', line 41

def nodes
  @nodes
end

Class Method Details

.map_path_to_parent(node, example_info) ⇒ Object



66
67
68
69
70
71
72
# File 'lib/jasmine-parser/node_collector.rb', line 66

def self.map_path_to_parent(node, example_info)
  if node.parent
   example_info[:name]  = node.formatted_name + example_info[:name] if node.formatted_name
   example_info[:backtrace] << "#{node.filename}:#{node.line}:in `#{node.name}'"
   self.map_path_to_parent(node.parent, example_info)
  end
end

Instance Method Details

#drill_down(nodes, type_wanted, collection, refine_search) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/jasmine-parser/node_collector.rb', line 49

def drill_down(nodes, type_wanted, collection, refine_search)
  nodes.each do |node|
    type_match = node.type == type_wanted
    refine_match = true
    if !refine_search.empty?
      refine_results = refine_search.keys.collect do |key|
        node.send(key.to_sym) == refine_search[key] if node.respond_to? :adoptable?
      end
      refine_match = false if refine_results.include? false
    end


    collection << node if type_match and refine_match
    drill_down node.children, type_wanted, collection, refine_search
  end
end

#find_by_name(name) ⇒ Object Also known as: []



36
37
38
# File 'lib/jasmine-parser/node_collector.rb', line 36

def find_by_name(name)
  name_key_hash(nodes)[name]
end