Class: AtomicAssessmentsImport::ExamSoft::Chunker::NumberedQuestionStrategy
- Inherits:
-
Strategy
- Object
- Strategy
- AtomicAssessmentsImport::ExamSoft::Chunker::NumberedQuestionStrategy
- Defined in:
- lib/atomic_assessments_import/exam_soft/chunker/numbered_question_strategy.rb
Constant Summary collapse
- NUMBERED_PATTERN =
Matches "1)" or "1." or "1" or "12)" etc. at start of text, but NOT single letters like "a)" because those are used for options, not question numbering We also allow for an optional "Question" prefix, e.g. "Question 1)" or "Question #: 1" NUMBERED_PATTERN = /\A\s*(\d+)\s*[.)]/
/\A\s*(?:Question\s*[:#]?\s*)?(\d+)\s*[.)]/
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
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/atomic_assessments_import/exam_soft/chunker/numbered_question_strategy.rb', line 14 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?(NUMBERED_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? found_first ? chunks : [] end |