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



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

#directivesArray<String>



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

def directives
  @directives
end

#disambigObject

Returns the value of attribute disambig.



22
23
24
# File 'lib/metanorma/collection.rb', line 22

def disambig
  @disambig
end

#documentsHash<String, Metanorma::Document>



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

def documents
  @documents
end

#fileString (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_exitObject

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_xmlString



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