Module: Metanorma::Collection::Config::Converters
Instance Method Summary collapse
- #bibdata_from_xml(model, node) ⇒ Object
- #bibdata_from_yaml(model, value) ⇒ Object
- #bibdata_to_xml(model, parent, doc) ⇒ Object
- #bibdata_to_yaml(model, doc) ⇒ Object
- #documents_from_xml(model, value) ⇒ Object
- #documents_to_xml(model, parent, doc) ⇒ Object
- #documents_to_xml?(doc) ⇒ Boolean
- #nop_to_yaml(model, doc) ⇒ Object
Instance Method Details
#bibdata_from_xml(model, node) ⇒ Object
16 17 18 19 |
# File 'lib/metanorma/collection/config/converters.rb', line 16 def bibdata_from_xml(model, node) node and model.bibdata = Relaton::Cli.parse_xml(node.node.adapter_node) end |
#bibdata_from_yaml(model, value) ⇒ Object
7 8 9 10 |
# File 'lib/metanorma/collection/config/converters.rb', line 7 def bibdata_from_yaml(model, value) value and !value.empty? or return model.bibdata = Relaton::Cli::YAMLConvertor.convert_single_file(value) end |
#bibdata_to_xml(model, parent, doc) ⇒ Object
21 22 23 24 25 |
# File 'lib/metanorma/collection/config/converters.rb', line 21 def bibdata_to_xml(model, parent, doc) b = model.bibdata or return elem = b.to_xml(bibdata: true, date_format: :full) doc.add_element(parent, elem) end |
#bibdata_to_yaml(model, doc) ⇒ Object
12 13 14 |
# File 'lib/metanorma/collection/config/converters.rb', line 12 def bibdata_to_yaml(model, doc) doc["bibdata"] = model.bibdata&.to_hash end |
#documents_from_xml(model, value) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/metanorma/collection/config/converters.rb', line 29 def documents_from_xml(model, value) model.documents = value .each_with_object([]) do |b, m| m << b end end |
#documents_to_xml(model, parent, doc) ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/metanorma/collection/config/converters.rb', line 36 def documents_to_xml(model, parent, doc) documents_to_xml?(doc) or return b = Nokogiri::XML::Builder.new do |xml| xml.document do |m| model.collection.doccontainer(m) or return end end b.parent.elements.first.elements .each { |x| doc.add_element(parent, x) } end |
#documents_to_xml?(doc) ⇒ Boolean
47 48 49 50 51 52 |
# File 'lib/metanorma/collection/config/converters.rb', line 47 def documents_to_xml?(doc) ret = doc.parent.elements.detect do |x| x.name == "doc-container" end !ret end |
#nop_to_yaml(model, doc) ⇒ Object
27 |
# File 'lib/metanorma/collection/config/converters.rb', line 27 def nop_to_yaml(model, doc); end |