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.



1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
# File 'lib/kamelopard/classes.rb', line 1136

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.



1133
1134
1135
# File 'lib/kamelopard/classes.rb', line 1133

def document_index
  @document_index
end

#documentsObject (readonly)

Returns the value of attribute documents.



1134
1135
1136
# File 'lib/kamelopard/classes.rb', line 1134

def documents
  @documents
end

#initializedObject

Returns the value of attribute initialized.



1133
1134
1135
# File 'lib/kamelopard/classes.rb', line 1133

def initialized
  @initialized
end

Instance Method Details

#<<(a) ⇒ Object



1165
1166
1167
1168
1169
# File 'lib/kamelopard/classes.rb', line 1165

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



1176
1177
1178
# File 'lib/kamelopard/classes.rb', line 1176

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

#[]=(i, v) ⇒ Object



1180
1181
1182
1183
# File 'lib/kamelopard/classes.rb', line 1180

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

#current_documentObject



1155
1156
1157
1158
1159
1160
1161
1162
1163
# File 'lib/kamelopard/classes.rb', line 1155

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

#set_current(a) ⇒ Object



1171
1172
1173
1174
# File 'lib/kamelopard/classes.rb', line 1171

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



1185
1186
1187
# File 'lib/kamelopard/classes.rb', line 1185

def size
    return @documents.size
end