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.
- #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.
-
#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
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/metanorma/collection.rb', line 30 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 end |
Instance Attribute Details
#directives ⇒ Array<String>
Returns documents-inline to inject the XML into the collection manifest; documents-external to keeps them outside.
16 17 18 |
# File 'lib/metanorma/collection.rb', line 16 def directives @directives end |
#documents ⇒ Hash<String, Metanorma::Document>
19 20 21 |
# File 'lib/metanorma/collection.rb', line 19 def documents @documents end |
#file ⇒ String (readonly)
12 13 14 |
# File 'lib/metanorma/collection.rb', line 12 def file @file end |
Class Method Details
.parse(file) ⇒ RelatonBib::BibliographicItem, RelatonIso::IsoBibliographicItem
74 75 76 77 78 79 |
# File 'lib/metanorma/collection.rb', line 74 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
47 48 49 |
# File 'lib/metanorma/collection.rb', line 47 def clean_exit @log.write(File.join(File.dirname(@file), File.basename(@file, ".*") + ".err")) end |
#render(opts) ⇒ Object
65 66 67 68 |
# File 'lib/metanorma/collection.rb', line 65 def render(opts) CollectionRenderer.render self, opts.merge(log: @log) clean_exit end |
#to_xml ⇒ String
Returns XML.
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/metanorma/collection.rb', line 52 def to_xml Nokogiri::XML::Builder.new do |xml| xml.send("metanorma-collection", "xmlns" => "http://metanorma.org") do |mc| mc << @bibdata.to_xml(bibdata: true, date_format: :full) @manifest.to_xml mc content_to_xml "prefatory", mc doccontainer mc content_to_xml "final", mc end end.to_xml end |