Class: Arachni::Support::LookUp::Base Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/arachni/support/lookup/base.rb

Overview

This class is abstract.

Author:

  • Tasos “Zapotek” Laskos <tasos.laskos@arachni-scanner.com>

Direct Known Subclasses

HashSet, Moolb

Constant Summary collapse

DEFAULT_OPTIONS =
{
    hasher: :hash
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Base

Returns a new instance of Base.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • (:hasher) (Symbol)

    Method to call on the item to obtain its hash.



27
28
29
30
# File 'lib/arachni/support/lookup/base.rb', line 27

def initialize( options = {} )
    @options = DEFAULT_OPTIONS.merge( options )
    @hasher  = @options[:hasher].to_sym
end

Instance Attribute Details

#collectionObject

Returns the value of attribute collection.



18
19
20
# File 'lib/arachni/support/lookup/base.rb', line 18

def collection
  @collection
end

Instance Method Details

#<<(item) ⇒ HashSet Also known as: add

Returns `self`.

Parameters:

  • item (#persistent_hash)

    Item to insert.

Returns:



37
38
39
40
# File 'lib/arachni/support/lookup/base.rb', line 37

def <<( item )
    @collection << calculate_hash( item )
    self
end

#==(other) ⇒ Object



77
78
79
# File 'lib/arachni/support/lookup/base.rb', line 77

def ==( other )
    hash == other.hash
end

#any?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/arachni/support/lookup/base.rb', line 65

def any?
    !empty?
end

#clearObject



73
74
75
# File 'lib/arachni/support/lookup/base.rb', line 73

def clear
    @collection.clear
end

#delete(item) ⇒ HashSet

Returns `self`.

Parameters:

  • item (#persistent_hash)

    Item to delete.

Returns:



48
49
50
51
# File 'lib/arachni/support/lookup/base.rb', line 48

def delete( item )
    @collection.delete( calculate_hash( item ) )
    self
end

#dupObject



85
86
87
# File 'lib/arachni/support/lookup/base.rb', line 85

def dup
    self.class.new( @options.dup ).tap { |c| c.collection = @collection.dup }
end

#empty?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/arachni/support/lookup/base.rb', line 61

def empty?
    @collection.empty?
end

#hashObject



81
82
83
# File 'lib/arachni/support/lookup/base.rb', line 81

def hash
    @collection.hash
end

#include?(item) ⇒ Bool

Parameters:

  • item (#persistent_hash)

    Item to check.

Returns:

  • (Bool)


57
58
59
# File 'lib/arachni/support/lookup/base.rb', line 57

def include?( item )
    @collection.include? calculate_hash( item )
end

#sizeObject



69
70
71
# File 'lib/arachni/support/lookup/base.rb', line 69

def size
    @collection.size
end