Module: Arachni::Parser::WithChildren::Search

Included in:
Arachni::Parser::WithChildren
Defined in:
lib/arachni/parser/with_children/search.rb

Instance Method Summary collapse

Instance Method Details

#descendantsObject


19
20
21
22
23
24
25
# File 'lib/arachni/parser/with_children/search.rb', line 19

def descendants
    @descendants ||= begin
        n = []
        traverse { |e| n << e }
        n
    end
end

#nodes_by_attribute_name(name) ⇒ Object


54
55
56
57
58
59
60
61
62
63
# File 'lib/arachni/parser/with_children/search.rb', line 54

def nodes_by_attribute_name( name )
    name = name.to_s.downcase

    @nodes_by_attribute_name ||= {}
    @nodes_by_attribute_name[name.hash] ||= begin
        descendants.select do |e|
            e.respond_to?(:attributes) && e.attributes.include?( name )
        end
    end
end

#nodes_by_attribute_name_and_value(name, value) ⇒ Object


65
66
67
68
69
70
71
72
73
74
# File 'lib/arachni/parser/with_children/search.rb', line 65

def nodes_by_attribute_name_and_value( name, value )
    name = name.to_s.downcase

    @nodes_by_attribute_name_and_value ||= {}
    @nodes_by_attribute_name_and_value[[name, value].hash] ||= begin
        nodes_by_attribute_name( name ).select do |e|
            e[name].to_s.downcase == value
        end
    end
end

#nodes_by_class(klass) ⇒ Object


27
28
29
30
31
32
33
34
# File 'lib/arachni/parser/with_children/search.rb', line 27

def nodes_by_class( klass )
    @nodes_by_name ||= {}
    @nodes_by_name[name] ||= begin
        descendants.select do |e|
            e.kind_of? klass
        end
    end
end

#nodes_by_name(name) ⇒ Object


36
37
38
39
40
41
42
43
44
45
# File 'lib/arachni/parser/with_children/search.rb', line 36

def nodes_by_name( name )
    name = name.to_s.downcase

    @nodes_by_name ||= {}
    @nodes_by_name[name.hash] ||= begin
        descendants.select do |e|
            e.respond_to?( :name ) && e.name == name.to_sym
        end
    end
end

#nodes_by_names(*names) ⇒ Object


47
48
49
50
51
52
# File 'lib/arachni/parser/with_children/search.rb', line 47

def nodes_by_names( *names )
    names = names.flatten

    @nodes_by_name ||= {}
    @nodes_by_name[names.hash] ||= names.map { |n| nodes_by_name( n ) }.flatten
end

#traverse(klass = nil, &block) ⇒ Object


15
16
17
# File 'lib/arachni/parser/with_children/search.rb', line 15

def traverse( klass = nil, &block )
    traverser children, klass, &block
end