Class: Punchlist::Inspector
- Inherits:
-
Object
- Object
- Punchlist::Inspector
- Defined in:
- lib/punchlist/inspector.rb
Overview
Inspects files for punchlist items
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#punchlist_line_regexp ⇒ Object
readonly
Returns the value of attribute punchlist_line_regexp.
Instance Method Summary collapse
-
#initialize(punchlist_line_regexp, filename, file_opener: File) ⇒ Inspector
constructor
A new instance of Inspector.
- #inspect_line(line) ⇒ Object
- #run ⇒ Object
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
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
8 9 10 |
# File 'lib/punchlist/inspector.rb', line 8 def filename @filename end |
#punchlist_line_regexp ⇒ Object (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 |
#run ⇒ Object
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 |