Class: Typingpool::Amazon::Question
- Inherits:
-
Object
- Object
- Typingpool::Amazon::Question
- 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
-
#html ⇒ Object
readonly
Returns the value of attribute html.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#annotation ⇒ Object
Returns URL-encoded key-value pairs that can be used as the text for a HIT#annotation.
-
#description ⇒ Object
Returns the description, extracted from the element with the id ‘description’ in the HTML.
-
#initialize(url, html) ⇒ Question
constructor
Constructor.
-
#title ⇒ Object
Returns the title, extracted from the title element of the HTML.
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
#html ⇒ Object (readonly)
Returns the value of attribute html.
10 11 12 |
# File 'lib/typingpool/amazon/question.rb', line 10 def html @html end |
#url ⇒ Object (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
#annotation ⇒ Object
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 |
#description ⇒ Object
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 |
#title ⇒ Object
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 |