Class: Metanorma::CollectionManifest
- Inherits:
-
Object
- Object
- Metanorma::CollectionManifest
- Defined in:
- lib/metanorma/collection_manifest.rb
Overview
Metanorma collection’s manifest
Instance Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
- #docref_by_id(docid) ⇒ Object
- #docrefs ⇒ Array<Hash{String=>String}>
- #documents(dir = "") ⇒ Hash<String, Metanorma::Document>
-
#initialize(level, title = nil, docref = [], manifest = []) ⇒ CollectionManifest
constructor
A new instance of CollectionManifest.
- #to_xml(builder) ⇒ Object
Constructor Details
#initialize(level, title = nil, docref = [], manifest = []) ⇒ CollectionManifest
Returns a new instance of CollectionManifest.
15 16 17 18 19 20 21 |
# File 'lib/metanorma/collection_manifest.rb', line 15 def initialize(level, title = nil, docref = [], manifest = []) @level = level @title = title @docref = docref @manifest = manifest @disambig = Util::DisambigFiles.new end |
Instance Attribute Details
#collection ⇒ Metanorma::Collection
9 10 11 |
# File 'lib/metanorma/collection_manifest.rb', line 9 def collection @collection end |
Class Method Details
.from_xml(mnf) ⇒ Metanorma::CollectionManifest
36 37 38 39 40 41 |
# File 'lib/metanorma/collection_manifest.rb', line 36 def from_xml(mnf) level = mnf.at("level").text title = mnf.at("title")&.text manifest = mnf.xpath("xmlns:manifest").map { |m| from_xml(m) } new(level, title, parse_docref(mnf), manifest) end |
.from_yaml(mnf) ⇒ Metanorma::CollectionManifest
26 27 28 29 30 31 32 |
# File 'lib/metanorma/collection_manifest.rb', line 26 def from_yaml(mnf) manifest = RelatonBib.array(mnf["manifest"]).map do |m| from_yaml m end docref = RelatonBib.array mnf["docref"] new(mnf["level"], mnf["title"], docref, manifest) end |
Instance Method Details
#docref_by_id(docid) ⇒ Object
98 99 100 101 102 |
# File 'lib/metanorma/collection_manifest.rb', line 98 def docref_by_id(docid) refs = docrefs dref = refs.detect { |k| k["identifier"] == docid } dref || docrefs.detect { |k| /^#{k["identifier"]}/ =~ docid } end |
#docrefs ⇒ Array<Hash{String=>String}>
91 92 93 94 95 96 |
# File 'lib/metanorma/collection_manifest.rb', line 91 def docrefs return @docrefs if @docrefs drfs = @docref.map { |dr| dr } @manifest.reduce(drfs) { |mem, mnf| mem + mnf.docrefs } end |
#documents(dir = "") ⇒ Hash<String, Metanorma::Document>
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/metanorma/collection_manifest.rb', line 67 def documents(dir = "") docs = @docref.each_with_object({}) do |dr, m| next m unless dr["fileref"] m[dr["identifier"]] = Document.parse_file( File.join(dir, dr["fileref"]), dr["attachment"], dr["identifier"], dr["index"] ) m end @manifest.reduce(docs) { |mem, mnf| mem.merge mnf.documents(dir) } end |
#to_xml(builder) ⇒ Object
81 82 83 84 85 86 87 88 |
# File 'lib/metanorma/collection_manifest.rb', line 81 def to_xml(builder) builder.manifest do |b| b.level @level b.title @title if @title docref_to_xml b @manifest.each { |m| m.to_xml b } end end |