Class: Finder

Inherits:
Object
  • Object
show all
Defined in:
lib/janitor/finder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = File.dirname(__FILE__)) ⇒ Finder

Returns a new instance of Finder.



4
5
6
# File 'lib/janitor/finder.rb', line 4

def initialize(path = File.dirname(__FILE__))
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



2
3
4
# File 'lib/janitor/finder.rb', line 2

def path
  @path
end

Instance Method Details

#exec_rak(pattern, options) ⇒ Object



22
23
24
# File 'lib/janitor/finder.rb', line 22

def exec_rak(pattern, options)
  RakResult.new(%x{rak #{options} #{pattern} #{@path}})
end

#hits(pattern) ⇒ Object



13
14
15
16
# File 'lib/janitor/finder.rb', line 13

def hits(pattern)
  rak_result = search_by_regex(pattern)
  rak_result.hits.collect { |hit| "#{hit.file_name}:#{hit.line_number}" }
end

#number_of_matches(pattern) ⇒ Object



8
9
10
11
# File 'lib/janitor/finder.rb', line 8

def number_of_matches(pattern)
  rak_result = search_by_regex(pattern)
  rak_result.hits.size
end

#search_by_regex(pattern) ⇒ Object



18
19
20
# File 'lib/janitor/finder.rb', line 18

def search_by_regex(pattern)
  exec_rak(pattern, '--all')
end