Class: AtomicAssessmentsImport::ExamSoft::Chunker::MetadataMarkerStrategy
- Inherits:
-
Strategy
- Object
- Strategy
- AtomicAssessmentsImport::ExamSoft::Chunker::MetadataMarkerStrategy
- Defined in:
- lib/atomic_assessments_import/exam_soft/chunker/metadata_marker_strategy.rb
Constant Summary collapse
- MARKER_PATTERN =
/\A\s*(?:Type:|Folder:)\s*/i
Instance Attribute Summary
Attributes inherited from Strategy
Instance Method Summary collapse
Methods inherited from Strategy
Constructor Details
This class inherits a constructor from AtomicAssessmentsImport::ExamSoft::Chunker::Strategy
Instance Method Details
#split(doc) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/atomic_assessments_import/exam_soft/chunker/metadata_marker_strategy.rb', line 11 def split(doc) @header_nodes = [] chunks = [] current_chunk = [] found_first = false doc.children.each do |node| text = node.text.strip next if text.empty? && !node.name.match?(/^(img|table|hr)$/i) if text.match?(MARKER_PATTERN) found_first = true chunks << current_chunk unless current_chunk.empty? current_chunk = [node] elsif found_first current_chunk << node else @header_nodes << node end end chunks << current_chunk unless current_chunk.empty? chunks end |