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.
- #size ⇒ Object
Constructor Details
#initialize(doc = nil) ⇒ DocumentHolder
Returns a new instance of DocumentHolder.
1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 |
# File 'lib/kamelopard/classes.rb', line 1099 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.
1096 1097 1098 |
# File 'lib/kamelopard/classes.rb', line 1096 def document_index @document_index end |
#documents ⇒ Object (readonly)
Returns the value of attribute documents.
1097 1098 1099 |
# File 'lib/kamelopard/classes.rb', line 1097 def documents @documents end |
#initialized ⇒ Object
Returns the value of attribute initialized.
1096 1097 1098 |
# File 'lib/kamelopard/classes.rb', line 1096 def initialized @initialized end |
Instance Method Details
#<<(a) ⇒ Object
1128 1129 1130 1131 1132 |
# File 'lib/kamelopard/classes.rb', line 1128 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
1134 1135 1136 |
# File 'lib/kamelopard/classes.rb', line 1134 def [](a) return @documents[a] end |
#[]=(i, v) ⇒ Object
1138 1139 1140 1141 |
# File 'lib/kamelopard/classes.rb', line 1138 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
1118 1119 1120 1121 1122 1123 1124 1125 1126 |
# File 'lib/kamelopard/classes.rb', line 1118 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 |
#size ⇒ Object
1143 1144 1145 |
# File 'lib/kamelopard/classes.rb', line 1143 def size return @documents.size end |