Class: Robot
- Inherits:
-
Object
- Object
- Robot
- Defined in:
- lib/form_robot/robot.rb
Instance Attribute Summary collapse
-
#failure_reason ⇒ Object
readonly
Returns the value of attribute failure_reason.
-
#was_successful ⇒ Object
readonly
Returns the value of attribute was_successful.
Instance Method Summary collapse
- #carry_out(instructions) ⇒ Object
-
#initialize ⇒ Robot
constructor
A new instance of Robot.
- #last_response ⇒ Object
Constructor Details
#initialize ⇒ Robot
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_reason ⇒ Object (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_successful ⇒ Object (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_response ⇒ Object
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 |