Module: Arrolio::GenericAdapter::DocumentExtraction
- Included in:
- Arrolio::GenericAdapter
- Defined in:
- lib/arrolio/generic_adapter/document_extraction.rb
Overview
Extracted conversion seam (TODO 56): one module per concern, included into the adapter. The class keeps dispatch and glue.
Instance Method Summary collapse
- #extract_bibliography(root) ⇒ Object
- #extract_preface(root) ⇒ Object
- #extract_sections(root) ⇒ Object
- #extract_title_block(root) ⇒ Object
- #title_block_runs(root) ⇒ Object
Instance Method Details
#extract_bibliography(root) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/arrolio/generic_adapter/document_extraction.rb', line 76 def extract_bibliography(root) biblio_elem = find_first(root, selector('bibliography_container')) return [] unless biblio_elem result = [] each_element(biblio_elem) do |child| next if child == biblio_elem next unless child.name == selector('bibliography_reference') items = [] each_child(child, selector('bibliography_item')) do |bi| items.concat(convert_bibitem(bi)) end result << Content::Section.new( title: 'Bibliography', level: 1, children: items, style_id: :section_body_1, title_style_id: title_style_for('bibliography', 1) ) end result end |
#extract_preface(root) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/arrolio/generic_adapter/document_extraction.rb', line 62 def extract_preface(root) preface_elem = find_first(root, selector('preface_container')) return [] unless preface_elem result = [] each_element(preface_elem) do |child| next if child == preface_elem next unless Array(selector('preface_children')).include?(child.name) result << convert_clause(child, context: :preface) end result end |
#extract_sections(root) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/arrolio/generic_adapter/document_extraction.rb', line 8 def extract_sections(root) sections_config = @rules['sections'] || {} container = sections_config['container'] || 'sections' sections_elem = find_first(root, container) return [] unless sections_elem children = [] each_direct_child(sections_elem) do |child| next unless map_element(child.name, sections_elem) == 'section' children << convert_clause(child) end children end |
#extract_title_block(root) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/arrolio/generic_adapter/document_extraction.rb', line 23 def extract_title_block(root) sections_config = @rules['sections'] || {} container = sections_config['container'] || 'sections' sections_elem = find_first(root, container) return nil unless sections_elem para_name = selector('paragraph') each_direct_child(sections_elem) do |child| next unless child.name == para_name cls = child.attribute('class')&.value title_style = (@rules['paragraph_styles'] || {})[cls] next unless title_style return Content::Paragraph.new( title_block_runs(root), style_id: title_style.to_sym, id: child.attribute(selector('id_attribute'))&.value ) end nil end |
#title_block_runs(root) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/arrolio/generic_adapter/document_extraction.rb', line 46 def title_block_runs(root) = (root) part = [:part_number].to_s title_part = [:title_part].to_s locality = @rules.dig('i18n', 'locality_part').to_s locality = 'Part' if locality.empty? text = if part.empty? && title_part.empty? '' elsif part.empty? title_part else "#{locality} #{part} - #{title_part}".strip end [Content::InlineRun.new(text, style_id: :doc_title)] end |