Class: Typingpool::Amazon::Question

Inherits:
Object
  • Object
show all
Defined in:
lib/typingpool/amazon/question.rb

Overview

Class encapsulating the HTML form presented to Mechanical Turk workers transcribing a Typingpool audio chunk.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, html) ⇒ Question

Constructor. Takes the URL of where the question HTML has been uploaded, followed by the question HTML itself.



14
15
16
17
# File 'lib/typingpool/amazon/question.rb', line 14

def initialize(url, html)
  @url = url
  @html = html
end

Instance Attribute Details

#htmlObject (readonly)

Returns the value of attribute html.



10
11
12
# File 'lib/typingpool/amazon/question.rb', line 10

def html
  @html
end

#urlObject (readonly)

Returns the value of attribute url.



10
11
12
# File 'lib/typingpool/amazon/question.rb', line 10

def url
  @url
end

Instance Method Details

#annotationObject

Returns URL-encoded key-value pairs that can be used as the text for a HIT#annotation. The key-value pairs correspond to all hidden HTML form fields in the question HTML.



22
23
24
# File 'lib/typingpool/amazon/question.rb', line 22

def annotation
  CGI.escapeHTML(URI.encode_www_form(Hash[*noko.css('input[type="hidden"]').select{|e| e['name'].match(/^typingpool_/) }.map{|e| [e['name'], e['value']]}.flatten]))
end

#descriptionObject

Returns the description, extracted from the element with the id ‘description’ in the HTML.



34
35
36
# File 'lib/typingpool/amazon/question.rb', line 34

def description
  noko.css('#description')[0].content
end

#titleObject

Returns the title, extracted from the title element of the HTML.



28
29
30
# File 'lib/typingpool/amazon/question.rb', line 28

def title
  noko.css('title')[0].content
end