Class: Punchlist::Inspector

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

Overview

Inspects files for punchlist items

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Inspector.



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

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 Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



8
9
10
# File 'lib/punchlist/inspector.rb', line 8

def filename
  @filename
end

#punchlist_line_regexpObject (readonly)

Returns the value of attribute punchlist_line_regexp.



8
9
10
# File 'lib/punchlist/inspector.rb', line 8

def punchlist_line_regexp
  @punchlist_line_regexp
end

Instance Method Details

#inspect_line(line) ⇒ Object



17
18
19
20
21
22
# File 'lib/punchlist/inspector.rb', line 17

def inspect_line(line)
  @line_num += 1
  return unless line =~ punchlist_line_regexp

  @lines << Offense.new(filename, @line_num, line.chomp)
end

#runObject



24
25
26
27
28
29
# File 'lib/punchlist/inspector.rb', line 24

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