Class: Finder
- Inherits:
-
Object
- Object
- Finder
- Defined in:
- lib/janitor/finder.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #exec_rak(pattern, options) ⇒ Object
- #hits(pattern) ⇒ Object
-
#initialize(path = File.dirname(__FILE__)) ⇒ Finder
constructor
A new instance of Finder.
- #number_of_matches(pattern) ⇒ Object
- #search_by_regex(pattern) ⇒ Object
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
#path ⇒ Object (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, ) RakResult.new(%x{rak #{} #{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 |