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.



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

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.



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

def document_index
  @document_index
end

#documentsObject (readonly)

Returns the value of attribute documents.



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

def documents
  @documents
end

#initializedObject

Returns the value of attribute initialized.



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

def initialized
  @initialized
end

Instance Method Details

#<<(a) ⇒ Object



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

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



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

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

#[]=(i, v) ⇒ Object



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

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

#current_documentObject



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

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



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

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



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

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



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

def size
    return @documents.size
end