Class: Ruber::World::MutableDocumentList
- Inherits:
-
DocumentList
- Object
- DocumentList
- Ruber::World::MutableDocumentList
- Defined in:
- lib/ruber/world/document_list.rb
Overview
A DocumentList which allows to change the contents of the list.
Instance Method Summary (collapse)
-
- (MutableDocumentList) add(*docs)
Adds documents to the list.
-
- (MutableDocumentList) clear
Removes all the elements from the list.
-
- (MutableDocumentList) clone
Override of
Object#clone
. -
- (MutableDocumentList) delete_if {|doc| ... }
Removes from the list all documents for which the block returns true.
-
- (MutableDocumentList) dup
Override of
Object#dup
. -
- (MutableDocumentList) initialize(docs = [])
constructor
A new instance of MutableDocumentList.
-
- (MutableDocumentList) merge!(other, remove_duplicates = true)
Adds the contents of another array or MutableDocumentList to the list.
-
- (Document?) remove(doc)
Removes a document from the list.
-
- (MutableDocumentList) uniq!
Ensures that the list doesn’t contain duplicates.
Methods inherited from DocumentList
#==, #[], #document_array, #document_for_file, #document_for_file?, #document_for_url, #document_for_url?, #document_with_name, #document_with_name?, #documents_with_file, #each, #empty?, #eql?, #hash, #size
Methods included from Enumerable
Constructor Details
- (MutableDocumentList) initialize(docs = [])
A new instance of MutableDocumentList
280 281 282 283 |
# File 'lib/ruber/world/document_list.rb', line 280 def initialize docs = [] docs = docs.document_array if docs.is_a? DocumentList @documents = docs.dup end |
Instance Method Details
- (MutableDocumentList) add(*docs)
this method doesn’t check for duplicate documents. While having multiple copies of the same document shouldn’t cause troubles, it’s better to avoid them. To do so, either check beforehand that docs contains no duplicates and no document already in the list, or use #uniq! afterwards
Adds documents to the list
318 319 320 321 322 |
# File 'lib/ruber/world/document_list.rb', line 318 def add *docs docs.flatten! @documents.insert -1, *docs self end |
- (MutableDocumentList) clear
Removes all the elements from the list
362 363 364 365 |
# File 'lib/ruber/world/document_list.rb', line 362 def clear @documents.clear self end |
- (MutableDocumentList) clone
Override of Object#clone
297 298 299 300 301 302 303 304 |
# File 'lib/ruber/world/document_list.rb', line 297 def clone res = self.class.new self if frozen? res.freeze res.document_array.freeze end res end |
- (MutableDocumentList) delete_if {|doc| ... }
Removes from the list all documents for which the block returns true
375 376 377 378 |
# File 'lib/ruber/world/document_list.rb', line 375 def delete_if &blk @documents.delete_if &blk self end |
- (MutableDocumentList) dup
Override of Object#dup
289 290 291 |
# File 'lib/ruber/world/document_list.rb', line 289 def dup self.class.new self end |
- (MutableDocumentList) merge!(other, remove_duplicates = true)
Adds the contents of another array or Ruber::World::MutableDocumentList to the list
The documents from the other list will be added at the end of this list.
336 337 338 339 340 341 342 343 |
# File 'lib/ruber/world/document_list.rb', line 336 def merge! other, remove_duplicates = true if other.is_a? DocumentList @documents.concat other.document_array else @documents.concat other end uniq! if remove_duplicates self end |
- (Document?) remove(doc)
Removes a document from the list
If the given document isn’t in the list, nothing is done
353 354 355 |
# File 'lib/ruber/world/document_list.rb', line 353 def remove doc @documents.delete doc end |
- (MutableDocumentList) uniq!
Ensures that the list doesn’t contain duplicates
After calling this method, the list won’t contain the same document in multiple places
387 388 389 390 |
# File 'lib/ruber/world/document_list.rb', line 387 def uniq! @documents.uniq! self end |