Class: Koine::TestRunner::FileMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/koine/test_runner/file_matcher.rb

Constant Summary collapse

NoMatchError =
Class.new(RuntimeError)

Instance Method Summary collapse

Constructor Details

#initialize(file_path:) ⇒ FileMatcher



6
7
8
# File 'lib/koine/test_runner/file_matcher.rb', line 6

def initialize(file_path:)
  @lines = File.readlines(file_path)
end

Instance Method Details

#above_line(line, regexp:) ⇒ Object

Raises:



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/koine/test_runner/file_matcher.rb', line 10

def above_line(line, regexp:)
  length = @lines.length
  slice = length - line
  lines = @lines.reverse.slice(slice, length)
  lines.each do |file_line|
    match = regexp.match(file_line)
    return match if match
  end

  raise NoMatchError
end