Class: RWB::Url

Inherits:
Object
  • Object
show all
Defined in:
lib/rwb/url.rb

Overview

The Url class holds individual URLs for testing. Urls are defined by a Fixnum representing the weight and a String representing the URL itself. The weights are not required to be percentages.

url = RWB::Url.new(20, "http://www.example.com")

Direct Known Subclasses

UrlGroup, UrlSession

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(weight, url, method = 'GET') ⇒ Url

Returns a new instance of Url.



12
13
14
15
16
# File 'lib/rwb/url.rb', line 12

def initialize(weight, url, method='GET')
  @weight = weight
  @url = url
  @method = read_method(method)
end

Instance Attribute Details

#methodObject (readonly)

Returns the value of attribute method.



10
11
12
# File 'lib/rwb/url.rb', line 10

def method
  @method
end

#weightObject (readonly)

Returns the value of attribute weight.



10
11
12
# File 'lib/rwb/url.rb', line 10

def weight
  @weight
end

Instance Method Details

#read_method(method = 'GET') ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/rwb/url.rb', line 18

def read_method(method = 'GET')
  method = method.to_s.upcase
  if method != 'GET' && method != 'POST'
    return 'GET'
  else
    return method
  end
end

#to_baseObject

to_base returns a string suitable for creating a Regexp to match against.

url.to_base # => "http://www.example.com "


40
41
42
# File 'lib/rwb/url.rb', line 40

def to_base
  @url
end

#to_sObject



44
45
46
# File 'lib/rwb/url.rb', line 44

def to_s
  @weight.to_s + " " + @url
end

#to_urlObject

to_url returns the URL to be requested as a string

url.to_url  # => "http://www.example.com"


30
31
32
# File 'lib/rwb/url.rb', line 30

def to_url
  @url
end