Class: AtomicAssessmentsImport::ExamSoft::Chunker::HorizontalRuleSplitStrategy
- Inherits:
-
Strategy
- Object
- Strategy
- AtomicAssessmentsImport::ExamSoft::Chunker::HorizontalRuleSplitStrategy
- Defined in:
- lib/atomic_assessments_import/exam_soft/chunker/horizontal_rule_split_strategy.rb
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
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/atomic_assessments_import/exam_soft/chunker/horizontal_rule_split_strategy.rb', line 9 def split(doc) @header_nodes = [] segments = [] current_segment = [] doc.children.each do |node| text = node.text.strip if node.name.match?(/^hr$/i) segments << current_segment unless current_segment.empty? current_segment = [] next end next if text.empty? && !node.name.match?(/^(img|table)$/i) current_segment << node end segments << current_segment unless current_segment.empty? @header_nodes = segments.shift if segments.length >= 3 segments.length >= 2 ? segments : [] end |