Class: Pronto::Punchlist::OffenseMatcher

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

Overview

Matches up the given offense with potentially matching lines

Instance Method Summary collapse

Constructor Details

#initialize(offense, message_creator: ::Pronto::Punchlist::MessageCreator.new) ⇒ OffenseMatcher

Returns a new instance of OffenseMatcher.



10
11
12
13
14
# File 'lib/pronto/punchlist/offense_matcher.rb', line 10

def initialize(offense,
               message_creator: ::Pronto::Punchlist::MessageCreator.new)
  @offense = offense
  @message_creator = message_creator
end

Instance Method Details

#inspect_line(line) ⇒ Object



24
25
26
27
28
# File 'lib/pronto/punchlist/offense_matcher.rb', line 24

def inspect_line(line)
  return nil unless line.new_lineno == @offense.line_num

  @message_creator.create(line.patch.delta.new_file[:path], line)
end

#inspect_patch(patch) ⇒ Object



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

def inspect_patch(patch)
  patch.added_lines.each do |line|
    message = inspect_line(line)
    return message unless message.nil?
  end
  nil
end