Class: Rubroxy::Handler::URLCapture

Inherits:
Object
  • Object
show all
Defined in:
lib/rubroxy/handlers/url_capture.rb

Overview

Captures URLs, stores the results in a hash as the handler Proc object is called.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHash

Creates a new URLCapture object. Sets up the hash to store URLs



11
12
13
# File 'lib/rubroxy/handlers/url_capture.rb', line 11

def initialize
  setup_collection
end

Instance Attribute Details

#collectionObject

Returns the value of attribute collection.



6
7
8
# File 'lib/rubroxy/handlers/url_capture.rb', line 6

def collection
  @collection
end

Instance Method Details

#clearHash

Clears the objects URL hash.

Returns:

  • (Hash)


32
33
34
# File 'lib/rubroxy/handlers/url_capture.rb', line 32

def clear
  setup_collection
end

#write(url) ⇒ Hash

Writes to the URL collection. It attempts to find the key matching the URL captured and increments the value if found. If not, it will create a new key value pair.

Parameters:

  • url (String)

    the url captured by the handler Proc

Returns:

  • (Hash)


21
22
23
24
25
26
27
# File 'lib/rubroxy/handlers/url_capture.rb', line 21

def write(url)
  if @collection[:uris].key?(url)
    @collection[:uris][url] += 1
  else
    @collection[:uris].merge!(url => 1)
  end
end