Class: Rindle::Index

Inherits:
Hash
  • Object
show all
Defined in:
lib/rindle/index.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeIndex

Returns a new instance of Index.



7
8
9
# File 'lib/rindle/index.rb', line 7

def initialize
  @index = {}
end

Class Method Details

.load(root_path) ⇒ Object



11
12
13
# File 'lib/rindle/index.rb', line 11

def self.load(root_path)
  Index.new.load(root_path)
end

Instance Method Details

#add(path) ⇒ Object

Adds a path to the index. This means that the correct sha1 sum is generated and used as index for the newly created document object.



27
28
29
30
31
# File 'lib/rindle/index.rb', line 27

def add path
  doc = Document.new path
  self[doc.index] = doc
  doc.index
end

#load(root_path) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/rindle/index.rb', line 15

def load(root_path)
  @root_path = root_path
  documents = Dir[File.join(@root_path, '{documents,pictures}', '*.{mobi,azw,azw1,pdf,rtf}')]
  documents.each do |element|
    add(element.gsub(@root_path, ''))
  end
  self
end

#remove(obj) ⇒ Object

Removes either an entry either by ‘Document` or index.



34
35
36
37
38
39
40
# File 'lib/rindle/index.rb', line 34

def remove obj
  if obj.is_a?(Document)
    delete(index(obj))
  else
    delete(obj)
  end
end