Class: Kamelopard::DocumentHolder
- Inherits:
-
Object
- Object
- Kamelopard::DocumentHolder
- 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
-
#document_index ⇒ Object
Returns the value of attribute document_index.
-
#documents ⇒ Object
readonly
Returns the value of attribute documents.
-
#initialized ⇒ Object
Returns the value of attribute initialized.
Instance Method Summary collapse
- #<<(a) ⇒ Object
- #[](a) ⇒ Object
- #[]=(i, v) ⇒ Object
- #current_document ⇒ Object
-
#initialize(doc = nil) ⇒ DocumentHolder
constructor
A new instance of DocumentHolder.
- #set_current(a) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(doc = nil) ⇒ DocumentHolder
Returns a new instance of DocumentHolder.
1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 |
# File 'lib/kamelopard/classes.rb', line 1131 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_index ⇒ Object
Returns the value of attribute document_index.
1128 1129 1130 |
# File 'lib/kamelopard/classes.rb', line 1128 def document_index @document_index end |
#documents ⇒ Object (readonly)
Returns the value of attribute documents.
1129 1130 1131 |
# File 'lib/kamelopard/classes.rb', line 1129 def documents @documents end |
#initialized ⇒ Object
Returns the value of attribute initialized.
1128 1129 1130 |
# File 'lib/kamelopard/classes.rb', line 1128 def initialized @initialized end |
Instance Method Details
#<<(a) ⇒ Object
1160 1161 1162 1163 1164 |
# File 'lib/kamelopard/classes.rb', line 1160 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
1171 1172 1173 |
# File 'lib/kamelopard/classes.rb', line 1171 def [](a) return @documents[a] end |
#[]=(i, v) ⇒ Object
1175 1176 1177 1178 |
# File 'lib/kamelopard/classes.rb', line 1175 def []=(i, v) raise "Cannot include a non-Document object in a DocumentHolder" unless v.kind_of? Document @documents[i] = v end |
#current_document ⇒ Object
1150 1151 1152 1153 1154 1155 1156 1157 1158 |
# File 'lib/kamelopard/classes.rb', line 1150 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
1166 1167 1168 1169 |
# File 'lib/kamelopard/classes.rb', line 1166 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 |
#size ⇒ Object
1180 1181 1182 |
# File 'lib/kamelopard/classes.rb', line 1180 def size return @documents.size end |