Class: Kamelopard::DocumentHolder

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/kamelopard/classes.rb

Overview

Holds a set of Document objects, so we can work with multiple KML files at once and keep track of them. It’s important for Kamelopard’s usability to have the concept of a “current” document, so we don’t have to specify the document we’re talking about each time we do something interesting. This class supports that idea.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(doc = nil) ⇒ DocumentHolder

Returns a new instance of DocumentHolder.



1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
# File 'lib/kamelopard/classes.rb', line 1284

def initialize(doc = nil)
    Kamelopard.log :debug, 'DocumentHolder', "document holder constructor"
    @documents = []
    @document_index = -1
    if ! doc.nil?
        Kamelopard.log :info, 'DocumentHolder', "Constructor called with a doc. Adding it."
        self.documents << doc
    end
    Kamelopard.log :debug, 'DocumentHolder', "document holder constructor finished"
end

Instance Attribute Details

#document_indexObject

Returns the value of attribute document_index.



1281
1282
1283
# File 'lib/kamelopard/classes.rb', line 1281

def document_index
  @document_index
end

#documentsObject (readonly)

Returns the value of attribute documents.



1282
1283
1284
# File 'lib/kamelopard/classes.rb', line 1282

def documents
  @documents
end

#initializedObject

Returns the value of attribute initialized.



1281
1282
1283
# File 'lib/kamelopard/classes.rb', line 1281

def initialized
  @initialized
end

Instance Method Details

#<<(a) ⇒ Object



1322
1323
1324
1325
1326
# File 'lib/kamelopard/classes.rb', line 1322

def <<(a)
    raise "Cannot add a non-Document object to a DocumentHolder" unless a.kind_of? Document
    @documents << a
    @document_index += 1
end

#[](a) ⇒ Object



1333
1334
1335
# File 'lib/kamelopard/classes.rb', line 1333

def [](a)
    return @documents[a]
end

#[]=(i, v) ⇒ Object



1337
1338
1339
1340
# File 'lib/kamelopard/classes.rb', line 1337

def []=(i, v)
    raise "Cannot include a non-Document object in a DocumentHolder" unless v.kind_of? Document
    @documents[i] = v
end

#current_documentObject



1312
1313
1314
1315
1316
1317
1318
1319
1320
# File 'lib/kamelopard/classes.rb', line 1312

def current_document
    # Automatically create a Document if we don't already have one
    if @documents.size <= 0
        Kamelopard.log :info, 'Document', "Doc doesn't exist... adding new one"
        Document.new
        @document_index = 0
    end
    return @documents[@document_index]
end

#delete_current_docObject



1303
1304
1305
1306
1307
1308
1309
1310
# File 'lib/kamelopard/classes.rb', line 1303

def delete_current_doc
    @documents.delete_at @document_index unless @document_index == -1
    if @documents.size > 0
        @document_index = @documents.size - 1
    else
        @document_index = -1
    end
end

#set_current(a) ⇒ Object



1328
1329
1330
1331
# File 'lib/kamelopard/classes.rb', line 1328

def set_current(a)
    raise "Must set current document to an existing Document object" unless a.kind_of? Document
    @document_index = @documents.index(a)
end

#sizeObject



1342
1343
1344
# File 'lib/kamelopard/classes.rb', line 1342

def size
    return @documents.size
end