Class: Ruber::World::DocumentFactory
- Defined in:
- lib/ruber/world/document_factory.rb
Overview
Note:
in the documentation, whenever a file name is mentioned, it can be replaced by a @KDE::Url@.
Factory class to create documents
It ensures that at all times there’s only a single document associated with a given file.
Instance Method Summary collapse
-
#document(file, parent = nil) ⇒ Document?
Returns a document, creating it if needed.
-
#initialize(parent = nil) ⇒ DocumentFactory
constructor
A new instance of DocumentFactory.
Constructor Details
#initialize(parent = nil) ⇒ DocumentFactory
Returns a new instance of DocumentFactory.
43 44 45 46 |
# File 'lib/ruber/world/document_factory.rb', line 43 def initialize parent = nil super @documents = {} end |
Instance Method Details
#document(file, parent = nil) ⇒ Document?
Returns a document, creating it if needed
If a file name is specified, a document for that file will be returned. If a document for that file name already exists, it will be returned. Otherwise, a new document will be created.
If no file or URL is given, a new document (not associated with a file) is returned.
65 66 67 68 69 70 71 72 73 |
# File 'lib/ruber/world/document_factory.rb', line 65 def document file, parent = nil if file url = KDE::Url.new file return if url.local_file? and !File.exist?(url.path) doc = @documents[url] doc || create_document(file, parent) else create_document nil, parent end end |