Class: Scruber::Helpers::UserAgentRotator

Inherits:
Object
  • Object
show all
Defined in:
lib/scruber/helpers/user_agent_rotator.rb

Defined Under Namespace

Classes: Configuration, UserAgent

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject



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

def configuration
  @configuration ||= Configuration.new
end

.cursorObject

Returns the value of attribute cursor.



53
54
55
# File 'lib/scruber/helpers/user_agent_rotator.rb', line 53

def cursor
  @cursor
end

Class Method Details

.configure(&block) ⇒ Object



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

def configure(&block)
  configuration.configure(&block)
end

.next(tags = nil) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/scruber/helpers/user_agent_rotator.rb', line 63

def next(tags=nil)
  raise Scruber::ArgumentError.new("UserAgent rotator not configured") if @configuration.nil?
  tags = @configuration.tags if tags.blank?
  user_agents = get_collection(tags)
  if @cursor.nil? || @cursor >= user_agents.count-1
    @cursor = 0
  else
    @cursor += 1
  end
  user_agents[@cursor].name
end