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.



1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
# File 'lib/kamelopard/classes.rb', line 1227

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.



1224
1225
1226
# File 'lib/kamelopard/classes.rb', line 1224

def document_index
  @document_index
end

#documentsObject (readonly)

Returns the value of attribute documents.



1225
1226
1227
# File 'lib/kamelopard/classes.rb', line 1225

def documents
  @documents
end

#initializedObject

Returns the value of attribute initialized.



1224
1225
1226
# File 'lib/kamelopard/classes.rb', line 1224

def initialized
  @initialized
end

Instance Method Details

#<<(a) ⇒ Object



1265
1266
1267
1268
1269
# File 'lib/kamelopard/classes.rb', line 1265

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



1276
1277
1278
# File 'lib/kamelopard/classes.rb', line 1276

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

#[]=(i, v) ⇒ Object



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

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

#current_documentObject



1255
1256
1257
1258
1259
1260
1261
1262
1263
# File 'lib/kamelopard/classes.rb', line 1255

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



1246
1247
1248
1249
1250
1251
1252
1253
# File 'lib/kamelopard/classes.rb', line 1246

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



1271
1272
1273
1274
# File 'lib/kamelopard/classes.rb', line 1271

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



1285
1286
1287
# File 'lib/kamelopard/classes.rb', line 1285

def size
    return @documents.size
end