Class: Duxml::Doc
- Includes:
- ElementGuts
- Defined in:
- lib/duxml/doc.rb
Instance Attribute Summary collapse
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
-
#path ⇒ Object
Returns the value of attribute path.
Attributes included from Reportable
Attributes included from Duxml
Attributes included from Saxer
Instance Method Summary collapse
-
#description ⇒ String
One word description of what this object is: ‘document’.
-
#grammar ⇒ Object
shortcut method @see Meta#grammar.
-
#grammar=(grammar_or_file) ⇒ Object
shortcut method @see Meta#grammar=.
-
#history ⇒ Object
shortcut method @see Meta#history.
-
#initialize(prolog = {}) ⇒ Doc
constructor
A new instance of Doc.
-
#set_meta(path_or_obj = nil) ⇒ Doc
Self.
-
#to_s ⇒ String
Summary of XML document as Ruby object and description of root element.
-
#write_to(path) ⇒ Doc
Returns self after writing contents to file.
Methods included from ElementGuts
#<<, #[], #[]=, #abstract?, #add, #dclone, #delete, #each, #inspect, #name_space, #sclone, #stub, #text?, #traverse
Methods included from LazyOx
Methods included from Reportable
Methods included from Duxml
Methods included from Saxer
Constructor Details
#initialize(prolog = {}) ⇒ Doc
Returns a new instance of Doc.
18 19 20 21 22 23 24 |
# File 'lib/duxml/doc.rb', line 18 def initialize(prolog={}) super(prolog) self[:version] ||= '1.0' = MetaClass.new @nodes = NodeSet.new(self) add_observer .history end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Duxml::LazyOx
Instance Attribute Details
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
16 17 18 |
# File 'lib/duxml/doc.rb', line 16 def end |
#path ⇒ Object
Returns the value of attribute path.
16 17 18 |
# File 'lib/duxml/doc.rb', line 16 def path @path end |
Instance Method Details
#description ⇒ String
Returns one word description of what this object is: ‘document’.
70 71 72 |
# File 'lib/duxml/doc.rb', line 70 def description 'document' end |
#grammar ⇒ Object
shortcut method @see Meta#grammar
55 56 57 |
# File 'lib/duxml/doc.rb', line 55 def grammar .grammar end |
#grammar=(grammar_or_file) ⇒ Object
shortcut method @see Meta#grammar=
60 61 62 |
# File 'lib/duxml/doc.rb', line 60 def grammar=(grammar_or_file) .grammar = grammar_or_file end |
#history ⇒ Object
shortcut method @see Meta#history
65 66 67 |
# File 'lib/duxml/doc.rb', line 65 def history .history end |
#set_meta(path_or_obj = nil) ⇒ Doc
Returns self.
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/duxml/doc.rb', line 42 def (path_or_obj=nil) = case path_or_obj when MetaClass, Element then path_or_obj when String && File.exists?(path_or_obj) Ox.parse_obj(path_or_obj) else File.write(Meta.(path), Ox.dump()) if path end self end |
#to_s ⇒ String
Returns summary of XML document as Ruby object and description of root element.
36 37 38 |
# File 'lib/duxml/doc.rb', line 36 def to_s "#<#{self.class.to_s} @object_id='#{object_id}' @root='#{root.nil? ? '' : root.description}'>" end |
#write_to(path) ⇒ Doc
Returns self after writing contents to file
76 77 78 79 80 81 82 |
# File 'lib/duxml/doc.rb', line 76 def write_to(path) s = attributes.collect do |k, v| %( #{k}="#{v}") end.join File.write(path, %(<?xml #{s}?>\n) + root.to_s) x = .xml File.write(Meta.(path), .xml.to_s) self end |