Class: AutoRedirector

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(agent) ⇒ AutoRedirector

Returns a new instance of AutoRedirector.



8
9
10
# File 'lib/auto_redirector.rb', line 8

def initialize(agent)
  self.set_agent(agent)
end

Instance Attribute Details

#agentObject

Returns the value of attribute agent.



6
7
8
# File 'lib/auto_redirector.rb', line 6

def agent
  @agent
end

Instance Method Details

#get(url) ⇒ Object



18
19
20
# File 'lib/auto_redirector.rb', line 18

def get(url)
  @agent.get(url)
end

#search(words) ⇒ Object



22
23
24
25
26
# File 'lib/auto_redirector.rb', line 22

def search(words)
  form = @agent.page.forms[0]
  form.fields[0].value = words
  form.submit
end

#set_agent(agent) ⇒ Object



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

def set_agent(agent)
  @agent = Mechanize.new do |a|
    a.user_agent_alias = agent
  end
end