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
- #force_primary_docidentifier_xml(node) ⇒ Object
- #force_primary_docidentifier_yaml(value) ⇒ Object
- #nop_to_yaml(model, doc) ⇒ Object
Instance Method Details
#bibdata_from_xml(model, node) ⇒ Object
30 31 32 33 34 |
# File 'lib/metanorma/collection/config/converters.rb', line 30 def bibdata_from_xml(model, node) node or return force_primary_docidentifier_xml(node.adapter_node) model.bibdata = Relaton::Cli.parse_xml(node.adapter_node) end |
#bibdata_from_yaml(model, value) ⇒ Object
7 8 9 10 11 |
# File 'lib/metanorma/collection/config/converters.rb', line 7 def bibdata_from_yaml(model, value) value and !value.empty? or return force_primary_docidentifier_yaml(value) model.bibdata = Relaton::Cli::YAMLConvertor.convert_single_file(value) end |
#bibdata_to_xml(model, parent, doc) ⇒ Object
42 43 44 45 46 |
# File 'lib/metanorma/collection/config/converters.rb', line 42 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
26 27 28 |
# File 'lib/metanorma/collection/config/converters.rb', line 26 def bibdata_to_yaml(model, doc) doc["bibdata"] = model.bibdata&.to_hash end |
#documents_from_xml(model, value) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/metanorma/collection/config/converters.rb', line 50 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
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/metanorma/collection/config/converters.rb', line 57 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
68 69 70 71 72 73 |
# File 'lib/metanorma/collection/config/converters.rb', line 68 def documents_to_xml?(doc) ret = doc.parent.elements.detect do |x| x.name == "doc-container" end !ret end |
#force_primary_docidentifier_xml(node) ⇒ Object
36 37 38 39 40 |
# File 'lib/metanorma/collection/config/converters.rb', line 36 def force_primary_docidentifier_xml(node) node.at("//docidentifier[@primary = 'true']") and return node d = node.at("//docidentifier") or return node d["primary"] = "true" end |
#force_primary_docidentifier_yaml(value) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/metanorma/collection/config/converters.rb', line 13 def force_primary_docidentifier_yaml(value) case value["docid"] when Array value["docid"].empty? || value["docid"].none? do |x| x["primary"] == "true" end or value["docid"].first["primary"] = "true" when Hash value["docid"]["primary"] ||= "true" end end |
#nop_to_yaml(model, doc) ⇒ Object
48 |
# File 'lib/metanorma/collection/config/converters.rb', line 48 def nop_to_yaml(model, doc); end |