Class: Rubygrep::GrepManager

Inherits:
Object
  • Object
show all
Defined in:
lib/rubygrep/grep_manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ GrepManager

Returns a new instance of GrepManager.



5
6
7
8
9
10
# File 'lib/rubygrep/grep_manager.rb', line 5

def initialize(options)
  @file_reader = FileReader.new(options.file_names, options.file_reader_options)
  options.set_multi_file_mode if @file_reader.has_several_files?
  @matcher = Matcher.new(options.expression, options.matcher_options)
  @outputter = Outputter.new(options.outputter_options)
end

Instance Attribute Details

#file_readerObject (readonly)

Returns the value of attribute file_reader.



3
4
5
# File 'lib/rubygrep/grep_manager.rb', line 3

def file_reader
  @file_reader
end

#matcherObject (readonly)

Returns the value of attribute matcher.



3
4
5
# File 'lib/rubygrep/grep_manager.rb', line 3

def matcher
  @matcher
end

#outputterObject (readonly)

Returns the value of attribute outputter.



3
4
5
# File 'lib/rubygrep/grep_manager.rb', line 3

def outputter
  @outputter
end

Instance Method Details

#runObject



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rubygrep/grep_manager.rb', line 12

def run
  file_reader.each_line do |line_data|
    begin
      match_data = matcher.matches?(line_data)
      if match_data
        outputter.out(match_data, line_data)
      end
    rescue Exception => e
      file_reader.next_file!
      outputter.error(e.message, line_data)
    end
  end
end