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)


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

#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



15
16
17
# File 'lib/metanorma/collection.rb', line 15

def directives
  @directives
end

#documentsHash<String, Metanorma::Document>

Returns:



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

def documents
  @documents
end

#fileString (readonly)

Returns:

  • (String)


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

def file
  @file
end

Class Method Details

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

Parameters:

  • file (String)

Returns:

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

Returns XML.

Returns:

  • (String)

    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