Class: Findrr::Database
- Inherits:
-
Object
- Object
- Findrr::Database
- Defined in:
- lib/findrr/database.rb
Instance Attribute Summary collapse
-
#base_dir ⇒ Object
Returns the value of attribute base_dir.
Instance Method Summary collapse
- #collect(target) ⇒ Object
- #destroy ⇒ Object
-
#initialize(base_dir = default_base_dir) ⇒ Database
constructor
A new instance of Database.
- #search(part_of_filename) ⇒ Object
Constructor Details
#initialize(base_dir = default_base_dir) ⇒ Database
Returns a new instance of Database.
8 9 10 11 |
# File 'lib/findrr/database.rb', line 8 def initialize(base_dir=default_base_dir) @base_dir = base_dir Groonga::Context. = {:encoding => :utf8} end |
Instance Attribute Details
#base_dir ⇒ Object
Returns the value of attribute base_dir.
7 8 9 |
# File 'lib/findrr/database.rb', line 7 def base_dir @base_dir end |
Instance Method Details
#collect(target) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/findrr/database.rb', line 13 def collect(target) create_database_dir create_database Groonga::Database.open(database_path) do files = Groonga["Files"] Find.find(File.(target)) do |path| unless files.has_key?(path) files.add(path, :basename => File.basename(path)) end end files.size end end |
#destroy ⇒ Object
40 41 42 43 |
# File 'lib/findrr/database.rb', line 40 def destroy FileUtils.rm(Dir.glob(File.join(database_dir, "findrr.db*"))) FileUtils.rmdir(database_dir) end |
#search(part_of_filename) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/findrr/database.rb', line 27 def search(part_of_filename) Groonga::Database.open(database_path) do files = Groonga["Files"] found_files = files.select do |record| record.basename =~ part_of_filename end found_files.each do |file| puts file._key.force_encoding("locale") end found_files.size end end |