Class: Metanorma::Document
- Inherits:
-
Object
- Object
- Metanorma::Document
- Defined in:
- lib/metanorma/document.rb
Instance Attribute Summary collapse
- #file ⇒ Strin readonly
Class Method Summary collapse
- .parse_file(file) ⇒ Metanorma::Document
-
.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 |
# File 'lib/metanorma/document.rb', line 7 def initialize(bibitem, file, = {}) @bibitem = bibitem @file = file @raw = [:raw] end |
Instance Attribute Details
#file ⇒ Strin (readonly)
4 5 6 |
# File 'lib/metanorma/document.rb', line 4 def file @file end |
Class Method Details
.parse_file(file) ⇒ Metanorma::Document
16 17 18 |
# File 'lib/metanorma/document.rb', line 16 def parse_file(file) new bibitem(file), file end |
.parse_xml(xml) ⇒ Metanorma::Document
#param xml [Nokogiri::XML::Document, Nokogiri::XML::Element]
22 23 24 |
# File 'lib/metanorma/document.rb', line 22 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
27 28 29 30 |
# File 'lib/metanorma/document.rb', line 27 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
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/metanorma/document.rb', line 65 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
77 78 79 80 81 |
# File 'lib/metanorma/document.rb', line 77 def type @type ||= (@bibitem.docidentifier.first&.type&.downcase || @bibitem.docidentifier.first&.id&.match(/^[^\s]+/)&.to_s)&.downcase || "standoc" end |