Class: Kitchen::TypeCastingElementEnumerator

Inherits:
ElementEnumeratorBase show all
Defined in:
lib/kitchen/type_casting_element_enumerator.rb

Overview

An enumerator that detects the element type as it iterates and returns specific, different element classes based on that type.

Instance Attribute Summary

Attributes inherited from ElementEnumeratorBase

#search_query

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ElementEnumeratorBase

#[], #chain_to, #chapters, #composite_chapters, #composite_pages, #copy, #cut, #examples, #exercises, #figures, #first!, #initialize, #injected_exercises, #injected_questions, #metadatas, #non_introduction_pages, #notes, #pages, #references, #search, #search_history, #search_with, #sections, #solutions, #tables, #terms, #titles, #to_s, #trash, #units

Methods included from Mixins::BlockErrorIf

#block_error_if

Constructor Details

This class inherits a constructor from Kitchen::ElementEnumeratorBase

Class Method Details

.factoryElementEnumeratorFactory

Returns a factory for this enumerator



13
14
15
16
17
18
# File 'lib/kitchen/type_casting_element_enumerator.rb', line 13

def self.factory
  ElementEnumeratorFactory.new(
    enumerator_class: self,
    detect_sub_element_class: true
  )
end

Instance Method Details

#only(*element_classes) ⇒ TypeCastingElementEnumerator

Returns a new enumerator that returns only the specified element classes within the scope of this enumerator.

Parameters:

  • element_classes (Array<ElementBase>)

    the element classes to limit iteration to

Returns:



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/kitchen/type_casting_element_enumerator.rb', line 26

def only(*element_classes)
  element_classes.flatten!

  TypeCastingElementEnumerator.new do |block|
    each do |element|
      next unless element_classes.include?(element.class)

      block.yield(element)
    end
  end
end