Class: GrepInteractors::GrepInPaths

Inherits:
Object
  • Object
show all
Defined in:
lib/grep_interactors/grep_in_paths.rb

Instance Method Summary collapse

Instance Method Details

#call(query, file_paths) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/grep_interactors/grep_in_paths.rb', line 5

def call(query, file_paths)
  file_paths.reduce([]) do |accum, file_path|
    lines = File.open(file_path).readlines

    accum + lines.each_with_index.map do |line, index|
      ("#{file_path}:#{index + 1}") if string_matcher.match?(line, query)
    end.compact
  end.flatten
end