Class: Scruber::Helpers::ProxyRotator::Configuration

Inherits:
Object
  • Object
show all
Includes:
Core::Extensions::Loop::CoreMethods
Defined in:
lib/scruber/helpers/proxy_rotator.rb

Constant Summary collapse

AVAILABLE_MODES =
[:random, :round_robin]

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Core::Extensions::Loop::CoreMethods

#add_dictionary, #loop

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



47
48
49
50
51
52
# File 'lib/scruber/helpers/proxy_rotator.rb', line 47

def initialize
  @mode = :round_robin
  @proxies = {}
  @proxy_keys = []
  @pickup = nil
end

Instance Attribute Details

#modeObject (readonly)

Returns the value of attribute mode.



45
46
47
# File 'lib/scruber/helpers/proxy_rotator.rb', line 45

def mode
  @mode
end

#pickupObject (readonly)

Returns the value of attribute pickup.



45
46
47
# File 'lib/scruber/helpers/proxy_rotator.rb', line 45

def pickup
  @pickup
end

#proxiesObject (readonly)

Returns the value of attribute proxies.



45
46
47
# File 'lib/scruber/helpers/proxy_rotator.rb', line 45

def proxies
  @proxies
end

#proxy_keysObject (readonly)

Returns the value of attribute proxy_keys.



45
46
47
# File 'lib/scruber/helpers/proxy_rotator.rb', line 45

def proxy_keys
  @proxy_keys
end

Instance Method Details

#add(proxy_address, options = {}) ⇒ Object



63
64
65
66
# File 'lib/scruber/helpers/proxy_rotator.rb', line 63

def add(proxy_address, options={})
  proxy = Proxy.new(proxy_address, options)
  @proxies[proxy.id] = proxy
end

#cleanObject



59
60
61
# File 'lib/scruber/helpers/proxy_rotator.rb', line 59

def clean
  @proxies = {}
end

#configure(&block) ⇒ Object



54
55
56
57
# File 'lib/scruber/helpers/proxy_rotator.rb', line 54

def configure(&block)
  instance_eval &block
  rebuild_caches
end

#set_mode(mode) ⇒ Object



68
69
70
71
72
73
74
# File 'lib/scruber/helpers/proxy_rotator.rb', line 68

def set_mode(mode)
  if AVAILABLE_MODES.include?(mode)
    @mode = mode
  else
    raise Scruber::ArgumentError.new("Wrong mode. Available modes: #{AVAILABLE_MODES}")
  end
end