Class: Metanorma::Collection
- Inherits:
-
Object
- Object
- Metanorma::Collection
- Defined in:
- lib/metanorma/collection.rb
Overview
Metanorma collection of documents
Instance Attribute Summary collapse
-
#bibdatas ⇒ Array<String>
Documents-inline to inject the XML into the collection manifest; documents-external to keeps them outside.
-
#coverpage ⇒ Array<String>
Documents-inline to inject the XML into the collection manifest; documents-external to keeps them outside.
-
#directives ⇒ Array<String>
Documents-inline to inject the XML into the collection manifest; documents-external to keeps them outside.
-
#dirname ⇒ Array<String>
Documents-inline to inject the XML into the collection manifest; documents-external to keeps them outside.
-
#disambig ⇒ Object
Returns the value of attribute disambig.
-
#documents ⇒ Array<String>
Documents-inline to inject the XML into the collection manifest; documents-external to keeps them outside.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#manifest ⇒ Object
Returns the value of attribute manifest.
Class Method Summary collapse
Instance Method Summary collapse
-
#clean_exit ⇒ Object
rubocop:enable Metrics/AbcSize,Metrics/MethodLength.
- #collection_body(coll) ⇒ Object
-
#initialize(**args) ⇒ Collection
constructor
rubocop:disable Metrics/AbcSize,Metrics/MethodLength.
- #obj_to_xml(elem) ⇒ Object
- #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 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/metanorma/collection.rb', line 30 def initialize(**args) @file = args[:file] @dirname = File.dirname(@file) @directives = args[:directives] || [] @bibdata = args[:bibdata] @manifest = args[:manifest] @manifest.collection = self @coverpage = Util::hash_key_detect(@directives, "coverpage", @coverpage) @coverpage_style = Util::hash_key_detect(@directives, "coverpage-style", @coverpage_style) @documents = args[:documents] || {} @bibdatas = args[:documents] || {} if @documents.any? && !@directives.include?("documents-inline") @directives << "documents-inline" end @documents.merge! @manifest.documents(@dirname) @bibdatas.merge! @manifest.documents(@dirname) @documents.transform_keys { |k| Util::key(k) } @bibdatas.transform_keys { |k| Util::key(k) } @prefatory = args[:prefatory] @final = args[:final] @compile = Metanorma::Compile.new @log = Metanorma::Utils::Log.new @disambig = Util::DisambigFiles.new end |
Instance Attribute Details
#bibdatas ⇒ 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 bibdatas @bibdatas end |
#coverpage ⇒ 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 coverpage @coverpage end |
#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 |
#dirname ⇒ 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 dirname @dirname end |
#disambig ⇒ Object
Returns the value of attribute disambig.
17 18 19 |
# File 'lib/metanorma/collection.rb', line 17 def disambig @disambig end |
#documents ⇒ 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 documents @documents end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
12 13 14 |
# File 'lib/metanorma/collection.rb', line 12 def file @file end |
#manifest ⇒ Object
Returns the value of attribute manifest.
17 18 19 |
# File 'lib/metanorma/collection.rb', line 17 def manifest @manifest end |
Class Method Details
.parse(file) ⇒ RelatonBib::BibliographicItem, RelatonIso::IsoBibliographicItem
106 107 108 109 110 111 |
# File 'lib/metanorma/collection.rb', line 106 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
57 58 59 60 |
# File 'lib/metanorma/collection.rb', line 57 def clean_exit @log.write(File.join(@dirname, "#{File.basename(@file, '.*')}.err.html")) end |
#collection_body(coll) ⇒ Object
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/metanorma/collection.rb', line 73 def collection_body(coll) coll << @bibdata.to_xml(bibdata: true, date_format: :full) @directives.each do |d| coll << "<directives>#{obj_to_xml(d)}</directives>" end @manifest.to_xml coll content_to_xml "prefatory", coll doccontainer coll content_to_xml "final", coll end |
#obj_to_xml(elem) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/metanorma/collection.rb', line 84 def obj_to_xml(elem) case elem when ::Array elem.each_with_object([]) do |v, m| m << "<value>#{obj_to_xml(v)}</value>" end.join when ::Hash elem.each_with_object([]) do |(k, v), m| m << "<#{k}>#{obj_to_xml(v)}</#{k}>" end.join else elem end end |
#render(opts) ⇒ Object
97 98 99 100 |
# File 'lib/metanorma/collection.rb', line 97 def render(opts) CollectionRenderer.render self, opts.merge(log: @log) clean_exit end |
#to_xml ⇒ String
Returns XML.
63 64 65 66 67 68 69 70 71 |
# File 'lib/metanorma/collection.rb', line 63 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 |