Class: Typingpool::Amazon::HIT::Full
- Inherits:
-
Object
- Object
- Typingpool::Amazon::HIT::Full
- Defined in:
- lib/typingpool/amazon/hit/full.rb,
lib/typingpool/amazon/hit/full/fromsearchhits.rb
Direct Known Subclasses
Defined Under Namespace
Classes: FromSearchHITs
Instance Attribute Summary collapse
-
#assignments_completed ⇒ Object
readonly
See the RTurk documentation and Amazon Mechanical Turk API documentation for more on these fields.
-
#assignments_duration ⇒ Object
readonly
See the RTurk documentation and Amazon Mechanical Turk API documentation for more on these fields.
-
#assignments_pending ⇒ Object
readonly
See the RTurk documentation and Amazon Mechanical Turk API documentation for more on these fields.
-
#expires_at ⇒ Object
readonly
See the RTurk documentation and Amazon Mechanical Turk API documentation for more on these fields.
-
#external_question_url ⇒ Object
readonly
See the RTurk documentation and Amazon Mechanical Turk API documentation for more on these fields.
-
#id ⇒ Object
readonly
See the RTurk documentation and Amazon Mechanical Turk API documentation for more on these fields.
-
#status ⇒ Object
readonly
See the RTurk documentation and Amazon Mechanical Turk API documentation for more on these fields.
-
#type_id ⇒ Object
readonly
See the RTurk documentation and Amazon Mechanical Turk API documentation for more on these fields.
Instance Method Summary collapse
-
#annotation ⇒ Object
Returns the HIT annotation as a hash.
-
#expired? ⇒ Boolean
Returns boolean indicated whether the HIT is expired.
-
#expired_and_overdue? ⇒ Boolean
Returns boolean indicated whether the HIT is expired and overdue, at which point it is totally safe to prune.
-
#external_question ⇒ Object
Returns the HTML of the external question associated with the HIT.
-
#external_question_param(param) ⇒ Object
Takes the name of an HTML form param and returns the value associated with that param in the external question HTML.
-
#initialize(rturk_hit) ⇒ Full
constructor
Constructor.
Constructor Details
#initialize(rturk_hit) ⇒ Full
Constructor. Takes an RTurk::HIT instance.
15 16 17 18 19 20 21 |
# File 'lib/typingpool/amazon/hit/full.rb', line 15 def initialize(rturk_hit) import_standard_attrs_from_rturk_hit(rturk_hit) @assignments_completed = rturk_hit.assignments_completed_count @assignments_pending = rturk_hit.assignments_pending_count self.annotation = rturk_hit.annotation self.external_question_url = rturk_hit.xml end |
Instance Attribute Details
#assignments_completed ⇒ Object (readonly)
See the RTurk documentation and Amazon Mechanical Turk API documentation for more on these fields.
12 13 14 |
# File 'lib/typingpool/amazon/hit/full.rb', line 12 def assignments_completed @assignments_completed end |
#assignments_duration ⇒ Object (readonly)
See the RTurk documentation and Amazon Mechanical Turk API documentation for more on these fields.
12 13 14 |
# File 'lib/typingpool/amazon/hit/full.rb', line 12 def assignments_duration @assignments_duration end |
#assignments_pending ⇒ Object (readonly)
See the RTurk documentation and Amazon Mechanical Turk API documentation for more on these fields.
12 13 14 |
# File 'lib/typingpool/amazon/hit/full.rb', line 12 def assignments_pending @assignments_pending end |
#expires_at ⇒ Object (readonly)
See the RTurk documentation and Amazon Mechanical Turk API documentation for more on these fields.
12 13 14 |
# File 'lib/typingpool/amazon/hit/full.rb', line 12 def expires_at @expires_at end |
#external_question_url ⇒ Object
See the RTurk documentation and Amazon Mechanical Turk API documentation for more on these fields.
12 13 14 |
# File 'lib/typingpool/amazon/hit/full.rb', line 12 def external_question_url @external_question_url end |
#id ⇒ Object (readonly)
See the RTurk documentation and Amazon Mechanical Turk API documentation for more on these fields.
12 13 14 |
# File 'lib/typingpool/amazon/hit/full.rb', line 12 def id @id end |
#status ⇒ Object (readonly)
See the RTurk documentation and Amazon Mechanical Turk API documentation for more on these fields.
12 13 14 |
# File 'lib/typingpool/amazon/hit/full.rb', line 12 def status @status end |
#type_id ⇒ Object (readonly)
See the RTurk documentation and Amazon Mechanical Turk API documentation for more on these fields.
12 13 14 |
# File 'lib/typingpool/amazon/hit/full.rb', line 12 def type_id @type_id end |
Instance Method Details
#annotation ⇒ Object
Returns the HIT annotation as a hash. If the annotation contained URL-encoded form key-value pairs, it decodes them and returns them as a hash. Otherwise, returns an empty hash (throwing away any annotation text that is not URL-encoded key-value pairs, for example the tags attached by the Amazon Mechanical Turk RUI).
29 30 31 |
# File 'lib/typingpool/amazon/hit/full.rb', line 29 def annotation @annotation ||= {} end |
#expired? ⇒ Boolean
Returns boolean indicated whether the HIT is expired. Determined by comparing the HIT’s expires_at attribute with the current time.
36 37 38 |
# File 'lib/typingpool/amazon/hit/full.rb', line 36 def expired? expires_at < Time.now end |
#expired_and_overdue? ⇒ Boolean
Returns boolean indicated whether the HIT is expired and overdue, at which point it is totally safe to prune. This is determined by adding the assignment duration (how long a worker has to complete the HIT) to the HIT’s expires_at time (when the HIT is removed from the Mechanical Turk marketplace).
46 47 48 |
# File 'lib/typingpool/amazon/hit/full.rb', line 46 def expired_and_overdue? (expires_at + assignments_duration) < Time.now end |
#external_question ⇒ Object
Returns the HTML of the external question associated with the HIT. All Typingpool HITs use external questions (as opposed to “internal” HIT QuestionForms), so this should always return something. In first use, must make an HTTP request to obtain the HTML.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/typingpool/amazon/hit/full.rb', line 55 def external_question if @external_question.nil? if external_question_url && external_question_url.match(/^http/) #expensive, obviously: begin @external_question = open(external_question_url).read rescue OpenURI::HTTPError => e #we don't worry about missing questions because those #should only be attached to HITs that aren't ours. we #take both 403 and 404 to mean missing because S3 #never returns 404, only 403. raise e unless e..match(/\b40[34]\b/) end #begin end #if external_question_url && external_question_url.match... end #if @external_question.nil? @external_question end |
#external_question_param(param) ⇒ Object
Takes the name of an HTML form param and returns the value associated with that param in the external question HTML. Triggers an HTTP request on first use (unless external_question has already been called).
77 78 79 80 81 82 83 |
# File 'lib/typingpool/amazon/hit/full.rb', line 77 def external_question_param(param) if external_question if input = Nokogiri::HTML::Document.parse(external_question).css("input[name=#{param}]")[0] return input['value'] end end end |