Class: RWB::UrlGroup
Overview
A UrlGroup is a collection of related URLs, for example the URL for a search tool, with several search queries. The group is weighted (and reported on) as a whole, but individual requests are made with random elements from an array of extensions.
urls = UrlGroup.new(20, "http://www.example.com/search?",
["foo", "bar", "baz"])
Instance Attribute Summary
Attributes inherited from Url
Instance Method Summary collapse
-
#initialize(weight, base, extension_array, method = 'GET') ⇒ UrlGroup
constructor
A new instance of UrlGroup.
-
#to_base ⇒ Object
to_base returns a String suitable for building a Regex to match against.
- #to_s ⇒ Object
-
#to_url(seed = nil) ⇒ Object
to_url returns a complete URL to be requested.
Methods inherited from Url
Constructor Details
#initialize(weight, base, extension_array, method = 'GET') ⇒ UrlGroup
Returns a new instance of UrlGroup.
60 61 62 63 64 65 |
# File 'lib/rwb/url.rb', line 60 def initialize(weight, base, extension_array, method='GET') @weight = weight.to_i @base = base.to_s @extension_array = extension_array @method = read_method(method) end |
Instance Method Details
#to_base ⇒ Object
to_base returns a String suitable for building a Regex to match against. This String will not include any extensions.
urls.to_base # => "http://www.example.com/search?"
88 89 90 |
# File 'lib/rwb/url.rb', line 88 def to_base @base end |
#to_s ⇒ Object
92 93 94 |
# File 'lib/rwb/url.rb', line 92 def to_s @weight.to_s + " " + @base end |
#to_url(seed = nil) ⇒ Object
to_url returns a complete URL to be requested. It takes an optional seed argument, which must be a Fixnum. If given, this will seed the random selection of the extension.
urls.to_url(1234) # => "http://www.example.com/search?baz"
75 76 77 78 79 80 |
# File 'lib/rwb/url.rb', line 75 def to_url(seed = nil) if seed srand = seed end @base + @extension_array[rand(@extension_array.length)] end |