Sha256: b25935926b17fb98ddb9f52caaa48c41d65f20a836c3a10a4d1c62c7abd36377

Contents?: true

Size: 738 Bytes

Versions: 1

Compression:

Stored size: 738 Bytes

Contents

# frozen_string_literal: true

require_relative 'offense'

module Punchlist
  # Inspects files for punchlist items
  class Inspector
    attr_reader :punchlist_line_regexp, :filename
    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

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

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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
punchlist-1.3.0 lib/punchlist/inspector.rb