Class: RWB::UrlGroup
- Inherits:
-
Object
- Object
- RWB::UrlGroup
- Defined in:
- lib/rwb.rb
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 collapse
-
#weight ⇒ Object
readonly
Returns the value of attribute weight.
Instance Method Summary collapse
-
#initialize(weight, base, extension_array) ⇒ 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.
Constructor Details
#initialize(weight, base, extension_array) ⇒ UrlGroup
Returns a new instance of UrlGroup.
54 55 56 57 58 |
# File 'lib/rwb.rb', line 54 def initialize(weight, base, extension_array) @weight = weight.to_i @base = base.to_s @extension_array = extension_array end |
Instance Attribute Details
#weight ⇒ Object (readonly)
Returns the value of attribute weight.
52 53 54 |
# File 'lib/rwb.rb', line 52 def weight @weight 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?"
80 81 82 |
# File 'lib/rwb.rb', line 80 def to_base @base end |
#to_s ⇒ Object
84 85 86 |
# File 'lib/rwb.rb', line 84 def to_s @weight + " " + @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"
67 68 69 70 71 72 |
# File 'lib/rwb.rb', line 67 def to_url(seed = nil) if seed srand = seed end @base + @extension_array[rand(@extension_array.length)] end |