Class: FuzzyNotes::FuzzyFinder

Inherits:
Object
  • Object
show all
Includes:
Logger
Defined in:
lib/fuzzy_notes/fuzzy_finder.rb

Constant Summary

Constants included from Logger::Colors

Logger::Colors::CREATE_COLOR, Logger::Colors::DEFAULT_COLOR, Logger::Colors::DELETE_COLOR, Logger::Colors::EXPORT_COLOR, Logger::Colors::IMPORT_COLOR, Logger::Colors::NOTE_COLOR, Logger::Colors::NUMBER_COLOR, Logger::Colors::PATH_COLOR, Logger::Colors::USER_COLOR

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logger

#log

Constructor Details

#initialize(path, params = {}) ⇒ FuzzyFinder

Returns a new instance of FuzzyFinder.



8
9
10
11
12
13
14
# File 'lib/fuzzy_notes/fuzzy_finder.rb', line 8

def initialize(path, params = {})
  @path = path
  log.debug "search path: #{path}"

  @keywords, @extensions, @search_type = params.values_at(:keywords, :extensions, :full_text_search)
  self.refresh
end

Instance Attribute Details

#all_filesObject (readonly)

Returns the value of attribute all_files.



6
7
8
# File 'lib/fuzzy_notes/fuzzy_finder.rb', line 6

def all_files
  @all_files
end

#extensionsObject (readonly)

Returns the value of attribute extensions.



6
7
8
# File 'lib/fuzzy_notes/fuzzy_finder.rb', line 6

def extensions
  @extensions
end

#files_matching_allObject (readonly)

Returns the value of attribute files_matching_all.



6
7
8
# File 'lib/fuzzy_notes/fuzzy_finder.rb', line 6

def files_matching_all
  @files_matching_all
end

#files_matching_extensionObject (readonly)

Returns the value of attribute files_matching_extension.



6
7
8
# File 'lib/fuzzy_notes/fuzzy_finder.rb', line 6

def files_matching_extension
  @files_matching_extension
end

#full_text_searchObject (readonly)

Returns the value of attribute full_text_search.



6
7
8
# File 'lib/fuzzy_notes/fuzzy_finder.rb', line 6

def full_text_search
  @full_text_search
end

#keywordsObject (readonly)

Returns the value of attribute keywords.



6
7
8
# File 'lib/fuzzy_notes/fuzzy_finder.rb', line 6

def keywords
  @keywords
end

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/fuzzy_notes/fuzzy_finder.rb', line 6

def path
  @path
end

Instance Method Details

#refreshObject



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/fuzzy_notes/fuzzy_finder.rb', line 16

def refresh
  clear_results
  Find.find(*@path) do |file_path| 
    if !File.directory?(file_path) 
       @all_files << file_path 
      if extension_match?(file_path)
        @files_matching_extension << file_path
        @files_matching_all << file_path if file_match_proc.call(file_path)
      end
    end
  end
end