Class: Metanorma::Mirror::MetanormaToMirror
- Inherits:
-
Object
- Object
- Metanorma::Mirror::MetanormaToMirror
- Defined in:
- lib/metanorma/mirror/metanorma_to_mirror.rb
Instance Attribute Summary collapse
-
#id_strategy ⇒ Object
readonly
Returns the value of attribute id_strategy.
-
#registry ⇒ Object
readonly
Returns the value of attribute registry.
Instance Method Summary collapse
- #call(root) ⇒ Object
- #extract_blocks(element) ⇒ Object
- #extract_named_collections(element, collection_attrs) ⇒ Object
- #extract_root_title(root) ⇒ Object
- #extract_section_children(element) ⇒ Object
-
#initialize(registry: Mirror.default_registry, id_strategy: Mirror.DEFAULT_ID_STRATEGY) ⇒ MetanormaToMirror
constructor
A new instance of MetanormaToMirror.
- #text_node(text, marks: []) ⇒ Object
Constructor Details
#initialize(registry: Mirror.default_registry, id_strategy: Mirror.DEFAULT_ID_STRATEGY) ⇒ MetanormaToMirror
Returns a new instance of MetanormaToMirror.
8 9 10 11 12 |
# File 'lib/metanorma/mirror/metanorma_to_mirror.rb', line 8 def initialize(registry: Mirror.default_registry, id_strategy: Mirror.DEFAULT_ID_STRATEGY) @registry = registry @id_strategy = id_strategy end |
Instance Attribute Details
#id_strategy ⇒ Object (readonly)
Returns the value of attribute id_strategy.
6 7 8 |
# File 'lib/metanorma/mirror/metanorma_to_mirror.rb', line 6 def id_strategy @id_strategy end |
#registry ⇒ Object (readonly)
Returns the value of attribute registry.
6 7 8 |
# File 'lib/metanorma/mirror/metanorma_to_mirror.rb', line 6 def registry @registry end |
Instance Method Details
#call(root) ⇒ 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 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/metanorma/mirror/metanorma_to_mirror.rb', line 14 def call(root) attrs = {} attrs[:flavor] = root.flavor if root.flavor attrs[:type] = root.type if root.type attrs[:schema_version] = root.schema_version if root.schema_version title = extract_root_title(root) attrs[:title] = title if title content = [] preface = root.preface if preface result = @registry.handle(preface, context: self) result.append_to(content) end sections = root.sections if sections result = @registry.handle(sections, context: self) result.append_to(content) end annex = root.annex annex&.each do |a| result = @registry.handle(a, context: self) result.append_to(content) end bibliography = root.bibliography if bibliography result = @registry.handle(bibliography, context: self) result.append_to(content) end Handlers.build_node("doc", attrs: attrs, content: content) end |
#extract_blocks(element) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/metanorma/mirror/metanorma_to_mirror.rb', line 52 def extract_blocks(element) content = [] element.each_mixed_content do |node| next if node.is_a?(String) result = @registry.handle(node, context: self) result.append_to(content) end content end |
#extract_named_collections(element, collection_attrs) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/metanorma/mirror/metanorma_to_mirror.rb', line 78 def extract_named_collections(element, collection_attrs) content = [] collection_attrs.each do |attr| collection = SafeAttr.read(element, attr) next unless collection collection.each do |child| result = @registry.handle(child, context: self) result.append_to(content) end end content end |
#extract_root_title(root) ⇒ Object
96 97 98 |
# File 'lib/metanorma/mirror/metanorma_to_mirror.rb', line 96 def extract_root_title(root) Metadata.title_from_bibdata(SafeAttr.read(root, :bibdata)) end |
#extract_section_children(element) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/metanorma/mirror/metanorma_to_mirror.rb', line 64 def extract_section_children(element) content = [] %i[clause terms definitions references floating_title].each do |attr| collection = SafeAttr.read(element, attr) next unless collection collection.each do |child| result = @registry.handle(child, context: self) result.append_to(content) end end content end |
#text_node(text, marks: []) ⇒ Object
92 93 94 |
# File 'lib/metanorma/mirror/metanorma_to_mirror.rb', line 92 def text_node(text, marks: []) Handlers.build_text(text, marks: marks) end |