Class: Recog::DBManager

Inherits:
Object
  • Object
show all
Defined in:
lib/recog/db_manager.rb

Constant Summary collapse

DefaultDatabasePath =
File.expand_path(File.join(File.expand_path(__dir__), ['..', '..', 'recog', 'xml']))

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = DefaultDatabasePath) ⇒ DBManager

Returns a new instance of DBManager.



12
13
14
15
# File 'lib/recog/db_manager.rb', line 12

def initialize(path = DefaultDatabasePath)
  self.path = path
  reload
end

Instance Attribute Details

#databasesObject

Returns the value of attribute databases.



8
9
10
# File 'lib/recog/db_manager.rb', line 8

def databases
  @databases
end

#pathObject

Returns the value of attribute path.



8
9
10
# File 'lib/recog/db_manager.rb', line 8

def path
  @path
end

Instance Method Details

#load_databasesObject



17
18
19
20
21
22
23
24
25
# File 'lib/recog/db_manager.rb', line 17

def load_databases
  if File.directory?(path)
    Dir["#{path}/*.xml"].each do |dbxml|
      databases << DB.new(dbxml)
    end
  else
    databases << DB.new(path)
  end
end

#reloadObject



27
28
29
30
# File 'lib/recog/db_manager.rb', line 27

def reload
  self.databases = []
  load_databases
end