Class: Duxml::Doc
- Includes:
- ElementGuts
- Defined in:
- lib/duxml/doc.rb
Instance Attribute Summary collapse
-
#id_hash ⇒ Object
readonly
Returns the value of attribute id_hash.
-
#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
- #<<(obj) ⇒ Object
-
#description ⇒ String
One word description of what this object is: ‘document’.
-
#find_by_id(id) ⇒ Element, NilClass
Found element or nil if not found.
-
#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, #set_doc!, #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.
21 22 23 24 25 26 27 28 |
# File 'lib/duxml/doc.rb', line 21 def initialize(prolog={}) super(prolog) self[:version] ||= '1.0' @id_hash = {} = 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
#id_hash ⇒ Object (readonly)
Returns the value of attribute id_hash.
19 20 21 |
# File 'lib/duxml/doc.rb', line 19 def id_hash @id_hash end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
19 20 21 |
# File 'lib/duxml/doc.rb', line 19 def end |
#path ⇒ Object
Returns the value of attribute path.
19 20 21 |
# File 'lib/duxml/doc.rb', line 19 def path @path end |
Instance Method Details
#<<(obj) ⇒ Object
88 89 90 91 92 |
# File 'lib/duxml/doc.rb', line 88 def <<(obj) super(obj) obj.set_doc! self self end |
#description ⇒ String
Returns one word description of what this object is: ‘document’.
74 75 76 |
# File 'lib/duxml/doc.rb', line 74 def description 'document' end |
#find_by_id(id) ⇒ Element, NilClass
Returns found element or nil if not found.
96 97 98 99 100 101 102 103 104 105 |
# File 'lib/duxml/doc.rb', line 96 def find_by_id(id) id_str = id.to_s return @id_hash[id_str] if @id_hash[id_str] root.traverse do |node| if node.respond_to?(:nodes) and node[:id] == id_str return @id_hash[id_str] = node end end nil end |
#grammar ⇒ Object
shortcut method @see Meta#grammar
59 60 61 |
# File 'lib/duxml/doc.rb', line 59 def grammar .grammar end |
#grammar=(grammar_or_file) ⇒ Object
shortcut method @see Meta#grammar=
64 65 66 |
# File 'lib/duxml/doc.rb', line 64 def grammar=(grammar_or_file) .grammar = grammar_or_file end |
#history ⇒ Object
shortcut method @see Meta#history
69 70 71 |
# File 'lib/duxml/doc.rb', line 69 def history .history end |
#set_meta(path_or_obj = nil) ⇒ Doc
Returns self.
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/duxml/doc.rb', line 46 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.
40 41 42 |
# File 'lib/duxml/doc.rb', line 40 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
80 81 82 83 84 85 86 |
# File 'lib/duxml/doc.rb', line 80 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 |