Class: Metanorma::Collection

Inherits:
Object
  • Object
show all
Defined in:
lib/metanorma/collection.rb

Overview

Metanorma collection of documents

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ Collection

rubocop:disable Metrics/AbcSize,Metrics/MethodLength

Parameters:

  • file (String)

    path to source file

  • directives (Array<String>)

    documents-inline to inject the XML into the collection manifest; documents-external to keeps them outside

  • bibdata (RelatonBib::BibliographicItem)
  • manifest (Metanorma::CollectionManifest)
  • documents (Hash<String, Metanorma::Document>)
  • prefatory (String)
  • final (String)


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

#directivesArray<String>

Returns documents-inline to inject the XML into the collection manifest; documents-external to keeps them outside.

Returns:

  • (Array<String>)

    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

#documentsHash<String, Metanorma::Document>

Returns:



19
20
21
# File 'lib/metanorma/collection.rb', line 19

def documents
  @documents
end

#fileString (readonly)

Returns:

  • (String)


12
13
14
# File 'lib/metanorma/collection.rb', line 12

def file
  @file
end

Class Method Details

.parse(file) ⇒ RelatonBib::BibliographicItem, RelatonIso::IsoBibliographicItem

Parameters:

  • file (String)

Returns:

  • (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_exitObject

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_xmlString

Returns XML.

Returns:

  • (String)

    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