Class: Metanorma::Document
- Inherits:
-
Object
- Object
- Metanorma::Document
- Defined in:
- lib/metanorma/document.rb
Instance Attribute Summary collapse
- #attachment ⇒ Strin readonly
- #bibitem ⇒ Strin readonly
- #file ⇒ Strin readonly
Class Method Summary collapse
- .attachment_bibitem(identifier) ⇒ Object
-
.parse_file(file, attachment, identifier = nil) ⇒ Metanorma::Document
in the collection file.
-
.parse_xml(xml) ⇒ Metanorma::Document
#param xml [Nokogiri::XML::Document, Nokogiri::XML::Element].
-
.raw_file(filename) ⇒ Object
raw XML file, can be used to put in entire file instead of just bibitem.
Instance Method Summary collapse
-
#initialize(bibitem, file, options = {}) ⇒ Document
constructor
A new instance of Document.
- #to_xml(builder = nil) ⇒ Nokogiri::XML::Builder, String
- #type ⇒ String
Constructor Details
#initialize(bibitem, file, options = {}) ⇒ Document
Returns a new instance of Document.
7 8 9 10 11 12 |
# File 'lib/metanorma/document.rb', line 7 def initialize(bibitem, file, = {}) @bibitem = bibitem @file = file @attachment = [:attachment] @raw = [:raw] end |
Instance Attribute Details
#attachment ⇒ Strin (readonly)
4 5 6 |
# File 'lib/metanorma/document.rb', line 4 def @attachment end |
#bibitem ⇒ Strin (readonly)
4 5 6 |
# File 'lib/metanorma/document.rb', line 4 def bibitem @bibitem end |
#file ⇒ Strin (readonly)
4 5 6 |
# File 'lib/metanorma/document.rb', line 4 def file @file end |
Class Method Details
.attachment_bibitem(identifier) ⇒ Object
37 38 39 40 41 |
# File 'lib/metanorma/document.rb', line 37 def (identifier) Nokogiri::XML( "<bibdata><docidentifier>#{identifier}</docidentifier></bibdata>", ) end |
.parse_file(file, attachment, identifier = nil) ⇒ Metanorma::Document
in the collection file
20 21 22 23 |
# File 'lib/metanorma/document.rb', line 20 def parse_file(file, , identifier = nil) new(bibitem(file, , identifier), file, { attachment: }) end |
.parse_xml(xml) ⇒ Metanorma::Document
#param xml [Nokogiri::XML::Document, Nokogiri::XML::Element]
27 28 29 |
# File 'lib/metanorma/document.rb', line 27 def parse_xml(xml) new from_xml(xml) end |
.raw_file(filename) ⇒ Object
raw XML file, can be used to put in entire file instead of just bibitem
32 33 34 35 |
# File 'lib/metanorma/document.rb', line 32 def raw_file(filename) doc = Nokogiri::XML(File.read(filename, encoding: "UTF-8")) new(doc, filename, raw: true) end |
Instance Method Details
#to_xml(builder = nil) ⇒ Nokogiri::XML::Builder, String
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/metanorma/document.rb', line 79 def to_xml(builder = nil) if builder render_xml builder else Nokogiri::XML::Builder.new do |b| root = render_xml b root["xmlns"] = "http://metanorma.org" end.to_xml end end |
#type ⇒ String
91 92 93 94 95 |
# File 'lib/metanorma/document.rb', line 91 def type @type ||= (@bibitem.docidentifier.first&.type&.downcase || @bibitem.docidentifier.first&.id&.match(/^[^\s]+/)&.to_s)&.downcase || "standoc" end |