Class: Linterbot::Patch
- Inherits:
-
Object
- Object
- Linterbot::Patch
- Defined in:
- lib/linterbot/patch.rb
Constant Summary collapse
- MODIFIED_FILE_DIFF_REGEXP =
/^@@ -\d+,\d+ \+(\d+),(\d+) @@.*$/
Instance Attribute Summary collapse
-
#patch_content ⇒ Object
Returns the value of attribute patch_content.
Instance Method Summary collapse
- #additions_ranges ⇒ Object
- #additions_ranges_for_hint(hint) ⇒ Object
- #chunks_headers ⇒ Object
- #included_in_patch?(hint) ⇒ Boolean
-
#initialize(patch_content) ⇒ Patch
constructor
A new instance of Patch.
Constructor Details
#initialize(patch_content) ⇒ Patch
Returns a new instance of Patch.
9 10 11 |
# File 'lib/linterbot/patch.rb', line 9 def initialize(patch_content) @patch_content = patch_content end |
Instance Attribute Details
#patch_content ⇒ Object
Returns the value of attribute patch_content.
7 8 9 |
# File 'lib/linterbot/patch.rb', line 7 def patch_content @patch_content end |
Instance Method Details
#additions_ranges ⇒ Object
17 18 19 20 21 22 |
# File 'lib/linterbot/patch.rb', line 17 def additions_ranges chunks_headers.map do |diff_header, line_number| match = diff_header.match(MODIFIED_FILE_DIFF_REGEXP) [match[1].to_i...match[2].to_i, line_number] end end |
#additions_ranges_for_hint(hint) ⇒ Object
24 25 26 |
# File 'lib/linterbot/patch.rb', line 24 def additions_ranges_for_hint(hint) additions_ranges.select { |diff_range, line_number| diff_range.include?(hint.line) } end |
#chunks_headers ⇒ Object
13 14 15 |
# File 'lib/linterbot/patch.rb', line 13 def chunks_headers @chunks_headers ||= parse_chunks_headers end |
#included_in_patch?(hint) ⇒ Boolean
28 29 30 |
# File 'lib/linterbot/patch.rb', line 28 def included_in_patch?(hint) additions_ranges_for_hint(hint).count > 0 end |