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
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 @meta 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) @meta = 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 |