Class: Duxml::Doc

Inherits:
Ox::Document
  • Object
show all
Includes:
ElementGuts
Defined in:
lib/duxml/doc.rb

Constant Summary

Constants included from Duxml

DITA_GRAMMAR

Constants included from Meta

Meta::FILE_EXT

Instance Attribute Summary

Attributes included from Duxml

#doc, #file, #meta

Attributes included from Saxer

#io

Instance Method Summary collapse

Methods included from ElementGuts

#<<, #[]=, #abstract?, #delete, #description, #each, #history, #inspect, #name_space, #stub, #traverse

Methods included from LazyOx

#method_missing

Methods included from Reportable

#add_observer

Methods included from Duxml

#create, #load, #log, #relaxng, #save, #validate

Methods included from Meta

#grammar=, meta_path, xml

Methods included from Saxer

#sax

Constructor Details

#initialize(prolog = {}) ⇒ Doc

Returns a new instance of Doc.



8
9
10
11
12
13
# File 'lib/duxml/doc.rb', line 8

def initialize(prolog={})
  super(prolog)
  self[:version] ||= '1.0'
  @nodes = NodeSet.new(self)
  # TODO should also create new metadata!!

end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Duxml::LazyOx

Instance Method Details

#to_sObject



22
23
24
# File 'lib/duxml/doc.rb', line 22

def to_s
  "#<#{self.class.to_s} @object_id='#{object_id}' @root='#{root.nil? ? '' : root.description}'>"
end

#write_to(path) ⇒ Object



15
16
17
18
19
20
# File 'lib/duxml/doc.rb', line 15

def write_to(path)
  s = attributes.collect do |k, v| %( #{k}="#{v}") end.join
  %(<?xml #{s}?>)+nodes.first.to_s
  File.write(path, s)
  self
end