require 'time' module RTurk # Parses: # # GYFTRHZ5J3DZREY48WNZE38ZR9RR1ZPMXGWE7WE0 # AD20WXZZP9XXK # GYFTRHZ5J3DZREY48WNZ # Approved # 2009-08-12T19:21:54Z # 2009-07-13T19:21:40Z # 2009-07-13T19:21:54Z # 2009-07-13T19:27:54Z # # # # # Question100 # Move to X. # # # # class Assignment include RTurk::XmlUtilities attr_accessor :worker_id, :id, :status, :submitted_at, :accepted_at, :approved_at attr_reader :answers def initialize(xml_object) map_content(xml_object, :id => 'AssignmentId', :worker_id => 'WorkerId', :status => 'AssignmentStatus', :accepted_at => 'AcceptTime', :approved_at => "ApprovalTime", :submitted_at => 'SubmitTime') self.answers = xml_object.xpath('Answer').children.to_s end def approved_at=(time) @approved_at = Time.parse(time) end def submitted_at=(time) @submitted_at = Time.parse(time) end def accepted_at=(time) @accepted_at = Time.parse(time) end def approve!(feedback = nil) RTurk::ApproveAssignment(:assignment_id => self.id, :feedback => feedback) end def reject!(reason) RTurk::ApproveAssignment(:assignment_id => self.id, :feedback => reason) end def bonus!(amount, reason) RTurk::GrantBonus(:amount, :feedback => reason) end def answers=(answer_xml) unless answer_xml.empty? @answers = RTurk::Answers.new(answer_xml) end end end end