Class: Scruber::Helpers::ProxyRotator::Proxy
- Defined in:
- lib/scruber/helpers/proxy_rotator.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#password ⇒ Object
Returns the value of attribute password.
-
#port ⇒ Object
Returns the value of attribute port.
-
#probability ⇒ Object
Returns the value of attribute probability.
-
#type ⇒ Object
Returns the value of attribute type.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
- #address ⇒ Object
- #http? ⇒ Boolean
- #id ⇒ Object
-
#initialize(proxy, options = {}) ⇒ Proxy
constructor
A new instance of Proxy.
- #proxyuserpwd ⇒ Object
Constructor Details
#initialize(proxy, options = {}) ⇒ Proxy
Returns a new instance of Proxy.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/scruber/helpers/proxy_rotator.rb', line 8 def initialize(proxy, ={}) @host = proxy.split(':', 2).first raise Scruber::ArgumentError.new("You need to specify proxy address") if @host.blank? @port = .fetch(:port) { proxy.split(':', 2)[1] }.to_i rescue nil raise Scruber::ArgumentError.new("You need to specify :port for this proxy or pass full proxy address like 127.0.0.1:100") if @port.nil? || @port.zero? @type = .fetch(:type) { 'http' } @user = .fetch(:user) { nil } @password = .fetch(:password) { nil } @probability = .fetch(:probability) { 1 } end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
6 7 8 |
# File 'lib/scruber/helpers/proxy_rotator.rb', line 6 def host @host end |
#password ⇒ Object
Returns the value of attribute password.
6 7 8 |
# File 'lib/scruber/helpers/proxy_rotator.rb', line 6 def password @password end |
#port ⇒ Object
Returns the value of attribute port.
6 7 8 |
# File 'lib/scruber/helpers/proxy_rotator.rb', line 6 def port @port end |
#probability ⇒ Object
Returns the value of attribute probability.
6 7 8 |
# File 'lib/scruber/helpers/proxy_rotator.rb', line 6 def probability @probability end |
#type ⇒ Object
Returns the value of attribute type.
6 7 8 |
# File 'lib/scruber/helpers/proxy_rotator.rb', line 6 def type @type end |
#user ⇒ Object
Returns the value of attribute user.
6 7 8 |
# File 'lib/scruber/helpers/proxy_rotator.rb', line 6 def user @user end |
Instance Method Details
#address ⇒ Object
23 24 25 |
# File 'lib/scruber/helpers/proxy_rotator.rb', line 23 def address @host + ':' + @port.to_s end |
#http? ⇒ Boolean
27 28 29 |
# File 'lib/scruber/helpers/proxy_rotator.rb', line 27 def http? @type == 'http' end |
#id ⇒ Object
19 20 21 |
# File 'lib/scruber/helpers/proxy_rotator.rb', line 19 def id (@host + ':' + @port.to_s) end |
#proxyuserpwd ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/scruber/helpers/proxy_rotator.rb', line 31 def proxyuserpwd if @user.blank? nil else "#{@user}:#{@password}" end end |