Class: Metanorma::Collection::Document
- Inherits:
-
Object
- Object
- Metanorma::Collection::Document
- Defined in:
- lib/metanorma/collection/document/document.rb
Instance Attribute Summary collapse
- #attachment ⇒ Strin readonly
- #bibitem ⇒ Strin readonly
- #file ⇒ Strin readonly
- #index ⇒ Strin readonly
Class Method Summary collapse
- .attachment_bibitem(identifier) ⇒ Object
-
.parse_file(file, attachment, identifier = nil, index = true) ⇒ 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.
10 11 12 13 14 15 16 17 |
# File 'lib/metanorma/collection/document/document.rb', line 10 def initialize(bibitem, file, = {}) @bibitem = bibitem @file = file @attachment = [:attachment] @index = [:index] @index = true if @index.nil? @raw = [:raw] end |
Instance Attribute Details
#attachment ⇒ Strin (readonly)
7 8 9 |
# File 'lib/metanorma/collection/document/document.rb', line 7 def @attachment end |
#bibitem ⇒ Strin (readonly)
7 8 9 |
# File 'lib/metanorma/collection/document/document.rb', line 7 def bibitem @bibitem end |
#file ⇒ Strin (readonly)
7 8 9 |
# File 'lib/metanorma/collection/document/document.rb', line 7 def file @file end |
#index ⇒ Strin (readonly)
7 8 9 |
# File 'lib/metanorma/collection/document/document.rb', line 7 def index @index end |
Class Method Details
.attachment_bibitem(identifier) ⇒ Object
43 44 45 46 47 |
# File 'lib/metanorma/collection/document/document.rb', line 43 def (identifier) Nokogiri::XML <<~DOCUMENT <bibdata><docidentifier>#{identifier}</docidentifier></bibdata> DOCUMENT end |
.parse_file(file, attachment, identifier = nil, index = true) ⇒ Metanorma::Document
in the collection file
26 27 28 29 |
# File 'lib/metanorma/collection/document/document.rb', line 26 def parse_file(file, , identifier = nil, index = true) new(bibitem(file, , identifier), file, { attachment: , index: index }) end |
.parse_xml(xml) ⇒ Metanorma::Document
#param xml [Nokogiri::XML::Document, Nokogiri::XML::Element]
33 34 35 |
# File 'lib/metanorma/collection/document/document.rb', line 33 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
38 39 40 41 |
# File 'lib/metanorma/collection/document/document.rb', line 38 def raw_file(filename) doc = Nokogiri::XML(File.read(filename, encoding: "UTF-8"), &:huge) new(doc, filename, raw: true) end |
Instance Method Details
#to_xml(builder = nil) ⇒ Nokogiri::XML::Builder, String
103 104 105 106 107 108 109 110 111 112 |
# File 'lib/metanorma/collection/document/document.rb', line 103 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
115 116 117 118 119 120 |
# File 'lib/metanorma/collection/document/document.rb', line 115 def type first = @bibitem.docidentifier.first @type ||= (first&.type&.downcase || first&.id&.match(/^[^\s]+/)&.to_s)&.downcase || "standoc" end |