Class: Punchlist::Inspector

Inherits:
Object
  • Object
show all
Defined in:
lib/punchlist/inspector.rb

Overview

Inspects files for punchlist items

Instance Method Summary collapse

Constructor Details

#initialize(punchlist_line_regexp, filename, file_opener: File) ⇒ Inspector

Returns a new instance of Inspector.

Parameters:

  • punchlist_line_regexp (Regexp)

    a regular expression that matches punchlist items

  • filename (String)

    the file to inspect

  • file_opener (Class<File>) (defaults to: File)

    an object that responds to ‘open` like `File`



11
12
13
14
15
16
17
# File 'lib/punchlist/inspector.rb', line 11

def initialize(punchlist_line_regexp, filename, file_opener: File)
  @file_opener = file_opener
  @punchlist_line_regexp = punchlist_line_regexp
  @filename = filename
  @lines = []
  @line_num = 0
end

Instance Method Details

#runArray<Offense>

Returns punchlist items for the specified file.

Returns:

  • (Array<Offense>)

    punchlist items for the specified file



20
21
22
23
24
25
# File 'lib/punchlist/inspector.rb', line 20

def run
  @file_opener.open(filename, 'r') do |file|
    file.each_line { |line| inspect_line(line) }
  end
  @lines
end