Class: Metanorma::Collection
- Inherits:
-
Object
- Object
- Metanorma::Collection
- Defined in:
- lib/metanorma/collection.rb
Overview
Metanorma collection of documents
Instance Attribute Summary collapse
-
#directives ⇒ Array<String>
Documents-inline to inject the XML into the collection manifest; documents-external to keeps them outside.
-
#disambig ⇒ Object
Returns the value of attribute disambig.
- #documents ⇒ Hash<String, Metanorma::Document>
- #file ⇒ String readonly
Class Method Summary collapse
Instance Method Summary collapse
-
#clean_exit ⇒ Object
rubocop:enable Metrics/AbcSize,Metrics/MethodLength.
- #collection_body(coll) ⇒ Object
-
#initialize(**args) ⇒ Collection
constructor
rubocop:disable Metrics/AbcSize,Metrics/MethodLength.
- #render(opts) ⇒ Object
-
#to_xml ⇒ String
XML.
Constructor Details
#initialize(**args) ⇒ Collection
rubocop:disable Metrics/AbcSize,Metrics/MethodLength
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/metanorma/collection.rb', line 33 def initialize(**args) @file = args[:file] @directives = args[:directives] || [] @bibdata = args[:bibdata] @manifest = args[:manifest] @manifest.collection = self @documents = args[:documents] || {} if @documents.any? && !@directives.include?("documents-inline") @directives << "documents-inline" end @documents.merge! @manifest.documents(File.dirname(@file)) @prefatory = args[:prefatory] @final = args[:final] @log = Metanorma::Utils::Log.new @disambig = Util::DisambigFiles.new end |
Instance Attribute Details
#directives ⇒ Array<String>
Returns documents-inline to inject the XML into the collection manifest; documents-external to keeps them outside.
17 18 19 |
# File 'lib/metanorma/collection.rb', line 17 def directives @directives end |
#disambig ⇒ Object
Returns the value of attribute disambig.
22 23 24 |
# File 'lib/metanorma/collection.rb', line 22 def disambig @disambig end |
#documents ⇒ Hash<String, Metanorma::Document>
20 21 22 |
# File 'lib/metanorma/collection.rb', line 20 def documents @documents end |
#file ⇒ String (readonly)
13 14 15 |
# File 'lib/metanorma/collection.rb', line 13 def file @file end |
Class Method Details
.parse(file) ⇒ RelatonBib::BibliographicItem, RelatonIso::IsoBibliographicItem
84 85 86 87 88 89 |
# File 'lib/metanorma/collection.rb', line 84 def parse(file) case file when /\.xml$/ then parse_xml(file) when /.ya?ml$/ then parse_yaml(file) end end |
Instance Method Details
#clean_exit ⇒ Object
rubocop:enable Metrics/AbcSize,Metrics/MethodLength
51 52 53 54 |
# File 'lib/metanorma/collection.rb', line 51 def clean_exit @log.write(File.join(File.dirname(@file), "#{File.basename(@file, '.*')}.err")) end |
#collection_body(coll) ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/metanorma/collection.rb', line 67 def collection_body(coll) coll << @bibdata.to_xml(bibdata: true, date_format: :full) @manifest.to_xml coll content_to_xml "prefatory", coll doccontainer coll content_to_xml "final", coll end |
#render(opts) ⇒ Object
75 76 77 78 |
# File 'lib/metanorma/collection.rb', line 75 def render(opts) CollectionRenderer.render self, opts.merge(log: @log) clean_exit end |
#to_xml ⇒ String
Returns XML.
57 58 59 60 61 62 63 64 65 |
# File 'lib/metanorma/collection.rb', line 57 def to_xml b = Nokogiri::XML::Builder.new do |xml| xml.send(:"metanorma-collection", "xmlns" => "http://metanorma.org") do |mc| collection_body(mc) end end b.to_xml end |