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
- #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.
7 8 9 10 11 12 13 14 |
# File 'lib/metanorma/document.rb', line 7 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)
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 |
#index ⇒ Strin (readonly)
4 5 6 |
# File 'lib/metanorma/document.rb', line 4 def index @index end |
Class Method Details
.attachment_bibitem(identifier) ⇒ Object
42 43 44 45 46 |
# File 'lib/metanorma/document.rb', line 42 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
23 24 25 26 |
# File 'lib/metanorma/document.rb', line 23 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]
30 31 32 |
# File 'lib/metanorma/document.rb', line 30 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
35 36 37 38 39 40 |
# File 'lib/metanorma/document.rb', line 35 def raw_file(filename) doc = Nokogiri::XML(File.read(filename, encoding: "UTF-8")) do |config| config.huge end new(doc, filename, raw: true) end |
Instance Method Details
#to_xml(builder = nil) ⇒ Nokogiri::XML::Builder, String
101 102 103 104 105 106 107 108 109 110 |
# File 'lib/metanorma/document.rb', line 101 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
113 114 115 116 117 118 |
# File 'lib/metanorma/document.rb', line 113 def type first = @bibitem.docidentifier.first @type ||= (first&.type&.downcase || first&.id&.match(/^[^\s]+/)&.to_s)&.downcase || "standoc" end |