Class: Kitchen::InjectedQuestionElement
- Inherits:
-
ElementBase
- Object
- ElementBase
- Kitchen::InjectedQuestionElement
- Defined in:
- lib/kitchen/injected_question_element.rb
Overview
An element for an example
Instance Attribute Summary
Attributes inherited from ElementBase
#ancestors, #document, #enumerator_class, #search_query_that_found_me, #short_type
Class Method Summary collapse
-
.short_type ⇒ Symbol
Returns the short type.
Instance Method Summary collapse
-
#answers ⇒ Element
Returns the list of answers as an element.
-
#correct_answer_letters(alphabet) ⇒ Array
Returns the answer correctness given an alphabet.
-
#exercise_context_in_question ⇒ Element
Returns the exercise context element.
-
#id ⇒ String
Returns or creates the question’s id.
-
#initialize(node:, document: nil) ⇒ InjectedQuestionElement
constructor
Creates a new
InjectedQuestionElement
. -
#solution ⇒ Element
Returns the solution element.
-
#stem ⇒ Element
Returns the question stem as an element.
-
#stimulus ⇒ Element
Returns the question stimulus as an element.
Methods inherited from ElementBase
#[], #[]=, #add_ancestor, #add_ancestors, #add_class, #ancestor, #ancestor_elements, #append, #as_enumerator, #children, #classes, #clone, #config, #contains?, #content, #copied_id, #copy, #count_in, #cut, #data_type, descendant, descendant!, #element_children, #first, #first!, #has_ancestor?, #has_class?, #href, #href=, #id=, #inner_html=, #inspect, #is?, is_the_element_class_for?, #key?, #mark_as_current_location!, #name, #name=, #pages, #pantry, #parent, #paste, #path, #preceded_by_text, #prepend, #previous, #raw, #raw_search, #remember_that_a_sub_element_was_counted, #remove_attribute, #remove_class, #replace_children, #search, #search_history, #selectors, #set, #sub_header_name, #target_label, #text, #to_html, #to_s, #to_xhtml, #to_xml, #trash, #uncount, #wrap, #wrap_children
Methods included from Mixins::BlockErrorIf
Constructor Details
#initialize(node:, document: nil) ⇒ InjectedQuestionElement
Creates a new InjectedQuestionElement
13 14 15 16 17 |
# File 'lib/kitchen/injected_question_element.rb', line 13 def initialize(node:, document: nil) super(node: node, document: document, enumerator_class: InjectedQuestionElementEnumerator) end |
Class Method Details
.short_type ⇒ Symbol
Returns the short type
22 23 24 |
# File 'lib/kitchen/injected_question_element.rb', line 22 def self.short_type :injected_question end |
Instance Method Details
#answers ⇒ Element
Returns the list of answers as an element.
46 47 48 |
# File 'lib/kitchen/injected_question_element.rb', line 46 def answers first("ol[data-type='question-answers']") end |
#correct_answer_letters(alphabet) ⇒ Array
Returns the answer correctness given an alphabet
69 70 71 72 73 74 |
# File 'lib/kitchen/injected_question_element.rb', line 69 def correct_answer_letters(alphabet) answers.search('li[data-type="question-answer"]').each_with_index.map \ do |answer, index| answer[:'data-correctness'] == '1.0' ? alphabet[index] : nil end.compact end |
#exercise_context_in_question ⇒ Element
Returns the exercise context element.
61 62 63 |
# File 'lib/kitchen/injected_question_element.rb', line 61 def exercise_context_in_question first("div[data-type='exercise-context']") end |
#id ⇒ String
Returns or creates the question’s id
80 81 82 |
# File 'lib/kitchen/injected_question_element.rb', line 80 def id self[:id] ||= "auto_#{ancestor(:page).id.gsub(/page_/, '')}_#{self[:'data-id']}" end |
#solution ⇒ Element
Returns the solution element.
54 55 56 |
# File 'lib/kitchen/injected_question_element.rb', line 54 def solution first("div[data-type='question-solution']") end |
#stem ⇒ Element
Returns the question stem as an element.
38 39 40 |
# File 'lib/kitchen/injected_question_element.rb', line 38 def stem first('div[data-type="question-stem"]') end |
#stimulus ⇒ Element
Returns the question stimulus as an element.
30 31 32 |
# File 'lib/kitchen/injected_question_element.rb', line 30 def stimulus first('div[data-type="question-stimulus"]') end |