Class: Kitchen::ExerciseElement
- Inherits:
-
ElementBase
- Object
- ElementBase
- Kitchen::ExerciseElement
- Defined in:
- lib/kitchen/exercise_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
-
#autogenerated_title ⇒ String
Get the autogenerated title for this note.
-
#baked? ⇒ Boolean
Returns whether the exercise has been baked.
- #detected_exercise_title_key ⇒ Object
-
#indicates_autogenerated_title? ⇒ Boolean
Returns true if the exercise’s title is autogenerated.
-
#initialize(node:, document: nil) ⇒ ExerciseElement
constructor
Creates a new
ExerciseElement
. -
#problem ⇒ Object
Returns the enumerator for problem.
-
#solution ⇒ Object
Returns the enumerator for solution.
-
#solutions ⇒ ElementEnumerator
Returns the enumerator for solutions.
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, #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) ⇒ ExerciseElement
Creates a new ExerciseElement
13 14 15 16 17 |
# File 'lib/kitchen/exercise_element.rb', line 13 def initialize(node:, document: nil) super(node: node, document: document, enumerator_class: ExerciseElementEnumerator) end |
Class Method Details
.short_type ⇒ Symbol
Returns the short type
22 23 24 |
# File 'lib/kitchen/exercise_element.rb', line 22 def self.short_type :exercise end |
Instance Method Details
#autogenerated_title ⇒ String
Get the autogenerated title for this note
70 71 72 73 74 75 76 |
# File 'lib/kitchen/exercise_element.rb', line 70 def autogenerated_title if indicates_autogenerated_title? I18n.t(:"exercises.#{detected_exercise_title_key}") else "unknown title for exercise with classes #{classes}" end end |
#baked? ⇒ Boolean
Returns whether the exercise has been baked
54 55 56 |
# File 'lib/kitchen/exercise_element.rb', line 54 def baked? search('div.os-problem-container').any? end |
#detected_exercise_title_key ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/kitchen/exercise_element.rb', line 78 def detected_exercise_title_key @detected_exercise_title_key ||= begin return 0 if classes.empty? || !I18n.t('.').key?(:exercises) possible_keys = I18n.t(:exercises).keys.map(&:to_s) keys = possible_keys & classes raise("too many translation keys: #{keys.join(', ')}") if keys.many? return 0 if keys.empty? keys.first end end |
#indicates_autogenerated_title? ⇒ Boolean
Returns true if the exercise’s title is autogenerated
62 63 64 |
# File 'lib/kitchen/exercise_element.rb', line 62 def indicates_autogenerated_title? detected_exercise_title_key != 0 && detected_exercise_title_key.present? end |
#problem ⇒ Object
Returns the enumerator for problem.
30 31 32 |
# File 'lib/kitchen/exercise_element.rb', line 30 def problem first("div[data-type='problem']") end |
#solution ⇒ Object
Returns the enumerator for solution.
38 39 40 |
# File 'lib/kitchen/exercise_element.rb', line 38 def solution first("div[data-type='solution']") end |
#solutions ⇒ ElementEnumerator
Returns the enumerator for solutions
46 47 48 |
# File 'lib/kitchen/exercise_element.rb', line 46 def solutions search("div[data-type='solution']") end |