Class: RTurk::Question
- Inherits:
-
Object
- Object
- RTurk::Question
- Defined in:
- lib/rturk/builders/question_builder.rb
Instance Attribute Summary (collapse)
-
- (Object) frame_height
Returns the value of attribute frame_height.
-
- (Object) url
Returns the value of attribute url.
-
- (Object) url_params
Returns the value of attribute url_params.
Instance Method Summary (collapse)
-
- (Question) initialize(url, opts = {})
constructor
A new instance of Question.
- - (Object) params
- - (Object) params=(param_set)
- - (Object) querystring
- - (Object) to_params
Constructor Details
- (Question) initialize(url, opts = {})
A new instance of Question
9 10 11 12 13 |
# File 'lib/rturk/builders/question_builder.rb', line 9 def initialize(url, opts = {}) @url = url self.frame_height = opts.delete(:frame_height) || 400 self.url_params = opts end |
Instance Attribute Details
- (Object) frame_height
Returns the value of attribute frame_height
7 8 9 |
# File 'lib/rturk/builders/question_builder.rb', line 7 def frame_height @frame_height end |
- (Object) url
Returns the value of attribute url
7 8 9 10 11 12 13 14 15 |
# File 'lib/rturk/builders/question_builder.rb', line 7 def url unless querystring.empty? # slam the params onto url, if url already has params, add 'em with a & u = @url.index('?') ? "#{@url}&#{querystring}" : "#{@url}?#{querystring}" else u = @url end CGI.escapeHTML(u) #URL should be XML/HTML escaped end |
- (Object) url_params
Returns the value of attribute url_params
7 8 9 |
# File 'lib/rturk/builders/question_builder.rb', line 7 def url_params @url_params end |
Instance Method Details
- (Object) params
29 30 31 |
# File 'lib/rturk/builders/question_builder.rb', line 29 def params @url_params end |
- (Object) params=(param_set)
33 34 35 |
# File 'lib/rturk/builders/question_builder.rb', line 33 def params=(param_set) @url_params = param_set end |
- (Object) querystring
15 16 17 |
# File 'lib/rturk/builders/question_builder.rb', line 15 def querystring @url_params.collect { |key, value| [CGI.escape(key.to_s), CGI.escape(value.to_s)].join('=') }.join('&') end |
- (Object) to_params
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/rturk/builders/question_builder.rb', line 37 def to_params raise RTurk::MissingParameters, "needs a url to build an external question" unless @url # TODO: update the xmlns schema... maybe xml = <<-XML <ExternalQuestion xmlns="http://mechanicalturk.amazonaws.com/AWSMechanicalTurkDataSchemas/2006-07-14/ExternalQuestion.xsd"> <ExternalURL>#{url}</ExternalURL> <FrameHeight>#{frame_height}</FrameHeight> </ExternalQuestion> XML xml end |