Class: RTurk::AssignmentParser

Inherits:
Parser
  • Object
show all
Defined in:
lib/rturk/parsers/assignment_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from XMLUtilities

#map_content, #normalize_nested_params, #xml_to_hash

Constructor Details

#initialize(assignment_xml) ⇒ AssignmentParser

Returns a new instance of AssignmentParser



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rturk/parsers/assignment_parser.rb', line 28

def initialize(assignment_xml)
  @xml_obj = assignment_xml
  map_content(@xml_obj,
              :assignment_id => 'AssignmentId',
              :hit_id => 'HITId',
              :worker_id => 'WorkerId',
              :status => 'AssignmentStatus',
              :accepted_at => 'AcceptTime',
              :submitted_at => 'SubmitTime',
              :approved_at => 'ApprovalTime',
              :auto_approval_time => 'AutoApprovalTime'
              )
end

Instance Attribute Details

#accepted_atObject (readonly)

Returns the value of attribute accepted_at



25
26
27
# File 'lib/rturk/parsers/assignment_parser.rb', line 25

def accepted_at
  @accepted_at
end

#approved_atObject (readonly)

Returns the value of attribute approved_at



25
26
27
# File 'lib/rturk/parsers/assignment_parser.rb', line 25

def approved_at
  @approved_at
end

#assignment_idObject (readonly)

Returns the value of attribute assignment_id



25
26
27
# File 'lib/rturk/parsers/assignment_parser.rb', line 25

def assignment_id
  @assignment_id
end

#auto_approval_timeObject (readonly)

Returns the value of attribute auto_approval_time



25
26
27
# File 'lib/rturk/parsers/assignment_parser.rb', line 25

def auto_approval_time
  @auto_approval_time
end

#hit_idObject (readonly)

Returns the value of attribute hit_id



25
26
27
# File 'lib/rturk/parsers/assignment_parser.rb', line 25

def hit_id
  @hit_id
end

#statusObject (readonly)

Returns the value of attribute status



25
26
27
# File 'lib/rturk/parsers/assignment_parser.rb', line 25

def status
  @status
end

#submitted_atObject (readonly)

Returns the value of attribute submitted_at



25
26
27
# File 'lib/rturk/parsers/assignment_parser.rb', line 25

def 
  @submitted_at
end

#worker_idObject (readonly)

Returns the value of attribute worker_id



25
26
27
# File 'lib/rturk/parsers/assignment_parser.rb', line 25

def worker_id
  @worker_id
end

Instance Method Details

#answersObject



42
43
44
# File 'lib/rturk/parsers/assignment_parser.rb', line 42

def answers
  AnswerParser.parse(@xml_obj.xpath('Answer').children)
end

#normalized_answersObject

Normalizes a hash of answers that include nested params such as the ones you'll find in Rails Example 'tweet' => 'Tweet!' becomes => {'text' => 'Tweet!'}



50
51
52
# File 'lib/rturk/parsers/assignment_parser.rb', line 50

def normalized_answers
  normalize_nested_params(answers)
end