Class: Scraypa::Throttle
- Inherits:
-
Object
- Object
- Scraypa::Throttle
- Defined in:
- lib/scraypa/throttle.rb
Instance Attribute Summary collapse
-
#last_request_time ⇒ Object
Returns the value of attribute last_request_time.
-
#seconds ⇒ Object
readonly
Returns the value of attribute seconds.
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ Throttle
constructor
A new instance of Throttle.
- #throttle ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Throttle
Returns a new instance of Throttle.
8 9 10 |
# File 'lib/scraypa/throttle.rb', line 8 def initialize params={} @seconds = params.fetch(:seconds, nil) end |
Instance Attribute Details
#last_request_time ⇒ Object
Returns the value of attribute last_request_time.
5 6 7 |
# File 'lib/scraypa/throttle.rb', line 5 def last_request_time @last_request_time end |
#seconds ⇒ Object (readonly)
Returns the value of attribute seconds.
6 7 8 |
# File 'lib/scraypa/throttle.rb', line 6 def seconds @seconds end |
Instance Method Details
#throttle ⇒ Object
12 13 14 15 16 17 |
# File 'lib/scraypa/throttle.rb', line 12 def throttle @seconds && @last_request_time ? (@seconds.is_a?(Hash) ? sleep_from_last_request_time_for( Random.new.rand(@seconds[:from]..@seconds[:to])) : sleep_from_last_request_time_for(@seconds)) : nil end |