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
-
#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
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/metanorma/collection.rb', line 29 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] end |
Instance Attribute Details
#directives ⇒ Array<String>
Returns documents-inline to inject the XML into the collection manifest; documents-external to keeps them outside.
15 16 17 |
# File 'lib/metanorma/collection.rb', line 15 def directives @directives end |
#documents ⇒ Hash<String, Metanorma::Document>
18 19 20 |
# File 'lib/metanorma/collection.rb', line 18 def documents @documents end |
#file ⇒ String (readonly)
11 12 13 |
# File 'lib/metanorma/collection.rb', line 11 def file @file end |
Class Method Details
.parse(file) ⇒ RelatonBib::BibliographicItem, RelatonIso::IsoBibliographicItem
67 68 69 70 71 72 |
# File 'lib/metanorma/collection.rb', line 67 def parse(file) case file when /\.xml$/ then parse_xml(file) when /.ya?ml$/ then parse_yaml(file) end end |
Instance Method Details
#render(opts) ⇒ Object
59 60 61 |
# File 'lib/metanorma/collection.rb', line 59 def render(opts) CollectionRenderer.render self, opts end |
#to_xml ⇒ String
Returns XML.
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/metanorma/collection.rb', line 46 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 |