Module: Enumerable

Defined in:
app/models/generic_grep.rb

Overview

String

Instance Method Summary collapse

Instance Method Details

#files_grep(pattern, delimiter = "\n") ⇒ Object

grep through multiple files Enumeration is list of filenames to grep (e.g. Dir) files opened


36
37
38
39
40
# File 'app/models/generic_grep.rb', line 36

def files_grep(pattern, delimiter="\n")
  map do |p|
    IO.read(p).split(delimiter).nested_grep(pattern, p)
  end.flatten #map
end

#nested_grep(pattern, context) ⇒ Object

Upgrade core grep with optional context If argument missing act just like core grep if context argument prsent, return it in a hash with answer Allows behavior like Unix command line grep with file glob, except now allows regexp with is more powerful. Chainable grep of enumeration


28
29
30
31
32
# File 'app/models/generic_grep.rb', line 28

def nested_grep(pattern, context)
  map do |e|
    e.single_grep(context, pattern)
  end.compact #map
end