Class: Typingpool::Amazon::HIT::Full

Inherits:
Object
  • Object
show all
Defined in:
lib/typingpool/amazon/hit/full.rb,
lib/typingpool/amazon/hit/full/fromsearchhits.rb

Direct Known Subclasses

FromSearchHITs

Defined Under Namespace

Classes: FromSearchHITs

Instance Attribute Summary collapse

Instance Method Summary collapse

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_completedObject (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_durationObject (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_pendingObject (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_atObject (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_urlObject

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

#idObject (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

#statusObject (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_idObject (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

#annotationObject

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.

Returns:

  • (Boolean)


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).

Returns:

  • (Boolean)


46
47
48
# File 'lib/typingpool/amazon/hit/full.rb', line 46

def expired_and_overdue?
  (expires_at + assignments_duration) < Time.now
end

#external_questionObject

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
# 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:
      @external_question = open(external_question_url).read
    end
  end
  @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).



69
70
71
72
73
74
75
# File 'lib/typingpool/amazon/hit/full.rb', line 69

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