Class: ClWiki::FindInFile
- Inherits:
- 
      Object
      
        - Object
- ClWiki::FindInFile
 
- Defined in:
- lib/cl_wiki/find_in_file.rb
Constant Summary collapse
- FULL_SEARCH =
- 0
- FILE_NAME_ONLY =
- 1
Instance Attribute Summary collapse
- 
  
    
      #files  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute files. 
- 
  
    
      #find_path  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute find_path. 
Instance Method Summary collapse
- #find(search_text, scope = FULL_SEARCH) ⇒ Object
- 
  
    
      #initialize(find_path)  ⇒ FindInFile 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of FindInFile. 
Constructor Details
#initialize(find_path) ⇒ FindInFile
Returns a new instance of FindInFile.
| 8 9 10 | # File 'lib/cl_wiki/find_in_file.rb', line 8 def initialize(find_path) @find_path = find_path end | 
Instance Attribute Details
#files ⇒ Object (readonly)
Returns the value of attribute files.
| 6 7 8 | # File 'lib/cl_wiki/find_in_file.rb', line 6 def files @files end | 
#find_path ⇒ Object (readonly)
Returns the value of attribute find_path.
| 6 7 8 | # File 'lib/cl_wiki/find_in_file.rb', line 6 def find_path @find_path end | 
Instance Method Details
#find(search_text, scope = FULL_SEARCH) ⇒ Object
| 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | # File 'lib/cl_wiki/find_in_file.rb', line 12 def find(search_text, scope = FULL_SEARCH) recursive_find_path = ::File.join(@find_path, '**', "*#{$wikiPageExt}") regex = /#{search_text}/i @files = Dir[recursive_find_path].grep(regex) if scope == FULL_SEARCH Dir[recursive_find_path].each do |path_filename| if ::File.stat(path_filename).file? f = ::File.open(path_filename) begin @files << path_filename if f.grep(regex) != [] ensure f.close unless f.nil? end end end end @files.collect! { |fn| fn.sub(@find_path + '/', '') } @files.uniq! @files.length end |