Class: BerkeleyLibrary::Util::ODS::XML::DocumentNode

Inherits:
Object
  • Object
show all
Defined in:
lib/berkeley_library/util/ods/xml/document_node.rb

Direct Known Subclasses

ContentDoc, ManifestDoc, StylesDoc

Constant Summary collapse

ENCODING =
'UTF-8'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ DocumentNode

Initializes a new DocumentNode

Parameters:

  • path (String)

    the path to this document in the container



15
16
17
# File 'lib/berkeley_library/util/ods/xml/document_node.rb', line 15

def initialize(path)
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



11
12
13
# File 'lib/berkeley_library/util/ods/xml/document_node.rb', line 11

def path
  @path
end

Instance Method Details

#docObject



26
27
28
29
30
# 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) ⇒ Object



19
20
21
22
23
24
# 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