Class: Robot

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRobot

Returns a new instance of Robot.



4
5
6
7
8
# File 'lib/form_robot/robot.rb', line 4

def initialize
    @mech = Mechanize.new
    @mech.user_agent_alias = 'Mac Safari'
    @was_succesful = false
end

Instance Attribute Details

#failure_reasonObject (readonly)

Returns the value of attribute failure_reason.



2
3
4
# File 'lib/form_robot/robot.rb', line 2

def failure_reason
  @failure_reason
end

#was_successfulObject (readonly)

Returns the value of attribute was_successful.



2
3
4
# File 'lib/form_robot/robot.rb', line 2

def was_successful
  @was_successful
end

Instance Method Details

#carry_out(instructions) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/form_robot/robot.rb', line 10

def carry_out ( instructions )
    if instructions.kind_of?(Array)
        instructions.all? { |i| carry_out(i) }
    else
        task = instructions
        @was_successful = carry_out_single( task )
        @failure_reason = 'Unable to ' + ( task[:description] || 'perform task' ) unless @was_successful
        @was_successful
    end
end

#last_responseObject



21
22
23
# File 'lib/form_robot/robot.rb', line 21

def last_response
    @mech.page.header.to_s + @mech.page.parser.to_s
end