class BerkeleyLibrary::Util::ODS::XML::DocumentNode
Constants
- ENCODING
Attributes
path[R]
Public Class Methods
new(path)
click to toggle source
Initializes a new DocumentNode
@param path [String] the path to this document in the container
# File lib/berkeley_library/util/ods/xml/document_node.rb, line 15 def initialize(path) @path = path end
Public Instance Methods
doc()
click to toggle source
# File lib/berkeley_library/util/ods/xml/document_node.rb, line 26 def doc @doc ||= Nokogiri::XML::Document.new.tap do |doc| doc.encoding = ENCODING end end
to_xml(out = nil, compact: true)
click to toggle source
# File lib/berkeley_library/util/ods/xml/document_node.rb, line 19 def to_xml(out = nil, compact: true) return write_xml_to_string(compact: compact) unless out return write_xml_to_stream(out, compact: compact) if out.respond_to?(:write) write_xml_to_file(out, compact: compact) end
Private Instance Methods
write_xml_to_file(path, compact:)
click to toggle source
# File lib/berkeley_library/util/ods/xml/document_node.rb, line 50 def write_xml_to_file(path, compact:) File.open(path, 'wb') { |f| write_xml_to_stream(f, compact: compact) } end
write_xml_to_stream(out, compact:)
click to toggle source
# File lib/berkeley_library/util/ods/xml/document_node.rb, line 34 def write_xml_to_stream(out, compact:) doc.root ||= root_element_node.element if compact doc.write_to(out, encoding: ENCODING, save_with: 0) else doc.write_to(out, encoding: ENCODING) end end
write_xml_to_string(compact:)
click to toggle source
# File lib/berkeley_library/util/ods/xml/document_node.rb, line 43 def write_xml_to_string(compact:) StringIO.new.tap do |out| out.binmode write_xml_to_stream(out, compact: compact) end.string end