class Rubroxy::Handler::URLCapture
Captures URLs, stores the results in a hash as the handler Proc object is called.
Attributes
collection[RW]
Public Class Methods
new()
click to toggle source
Creates a new URLCapture
object. Sets up the hash to store URLs
@return [Hash]
# File lib/rubroxy/handlers/url_capture.rb, line 11 def initialize setup_collection end
Public Instance Methods
clear()
click to toggle source
Clears the objects URL hash.
@return [Hash]
# File lib/rubroxy/handlers/url_capture.rb, line 32 def clear setup_collection end
write(url)
click to toggle source
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.
@param url [String] the url captured by the handler Proc @return [Hash]
# 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
Private Instance Methods
setup_collection()
click to toggle source
Called by public methods to setup the correct hash structure.
@return [Hash]
# File lib/rubroxy/handlers/url_capture.rb, line 41 def setup_collection @collection = { uris: {} } end