Class: MultiChoice::RadioButton

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

Overview

Arguments: over_view_text is the overview for the Question you are asking Mturkers identifier: format “Your_Name - HitNumber”, example “John_Smith-1” question: format “something you want to ask”, example “Which of these is a cat?” possibles: format [‘A tabby cat’, ‘Leo Di Caprio since his name is Leo’, ‘Cat Stevens’, ‘The Year of the Cat by Al Stewart because Seventies Man!’, ‘None of the Above’] possibles is the only argument that is NOT A STRING, but an array. possibles must have AT LEAST ONE ARRAY ELEMENT, which is at least one possible answer to the question. But to make sense to the Mturker workers you should have at least two, i.e possibles = [‘The Band Stray Cats’, ‘None of the Above’]

Instance Method Summary collapse

Constructor Details

#initialize(over_view_text, identifier, question, possibles) ⇒ RadioButton

Returns a new instance of RadioButton.



18
19
20
21
22
23
# File 'lib/multichoice.rb', line 18

def initialize(over_view_text, identifier, question, possibles)
  @over_view_text = over_view_text
  @identifier = identifier
  @question = question
  @possibles = possibles
end

Instance Method Details

#executeObject



25
26
27
# File 'lib/multichoice.rb', line 25

def execute
  spitoutxml
end

#spitoutxmlObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/multichoice.rb', line 29

def spitoutxml
  base_xml = <<HERE
<?xml version="1.0" encoding="UTF-8"?>
  <QuestionForm xmlns="http://mechanicalturk.amazonaws.com/AWSMechanicalTurkDataSchemas/2005-10-01/QuestionForm.xsd">
    <Overview>
    <Text>#{@over_view_text}</Text>
    </Overview>
    <Question>
HERE

  mylocal_identifier = "<QuestionIdentifier>#{@identifier}</QuestionIdentifier>"
  my_sku = "<QuestionContent>\n"
  my_sku = my_sku + "<Text>#{@question}</Text>\n"
  my_sku = my_sku + "</QuestionContent>\n"
  base_xml = base_xml + mylocal_identifier + my_sku

  top_answer_spec = <<ANS1
       <AnswerSpecification>
       <SelectionAnswer>
    <StyleSuggestion>radiobutton</StyleSuggestion>
    <Selections>
ANS1

  base_xml = base_xml + top_answer_spec
  my_answer = ''


  @possibles.each do |myelement|

      my_answer_spec = "<Selection>\n"
      spec_ident = "<SelectionIdentifier>#{myelement}</SelectionIdentifier>\n"
      sel_text = "<Text>#{myelement}</Text>\n"
      close_spec = "</Selection>\n"
      my_temp = my_answer_spec + spec_ident + sel_text + close_spec
      my_answer = my_answer + my_temp

     end


  base_xml = base_xml + my_answer

  bottom_answer = <<BOTTOM


    </Selections>
  </SelectionAnswer>
     </AnswerSpecification>
    </Question>
  </QuestionForm>
BOTTOM
  base_xml = base_xml + bottom_answer

  return base_xml
end