Class: Pronto::ClangFormat::Offence
- Inherits:
-
Object
- Object
- Pronto::ClangFormat::Offence
- Defined in:
- lib/pronto/clang_format/offence.rb
Instance Attribute Summary collapse
-
#affected_lines_before ⇒ Object
readonly
Returns the value of attribute affected_lines_before.
-
#column ⇒ Object
readonly
Returns the value of attribute column.
-
#length ⇒ Object
readonly
Returns the value of attribute length.
-
#line_no ⇒ Object
readonly
Returns the value of attribute line_no.
-
#offset ⇒ Object
readonly
Returns the value of attribute offset.
-
#replacement ⇒ Object
readonly
Returns the value of attribute replacement.
Instance Method Summary collapse
-
#affected_lines_after ⇒ Object
returns affected lines after fixing this offence.
-
#affected_lines_range ⇒ Object
returns the range of line numbers affected by this offence.
-
#initialize(offset, line_no, column, length, replacement, affected_lines) ⇒ Offence
constructor
A new instance of Offence.
-
#msg ⇒ Object
generates a user-friendly message that describes this offence.
-
#replaced_text ⇒ Object
the exact portion of text that is to be replaced by this offence.
Constructor Details
#initialize(offset, line_no, column, length, replacement, affected_lines) ⇒ Offence
Returns a new instance of Offence.
8 9 10 11 12 13 14 15 16 |
# File 'lib/pronto/clang_format/offence.rb', line 8 def initialize(offset, line_no, column, length, replacement, affected_lines) @offset = offset.freeze @line_no = line_no.freeze @column = column.freeze @length = length.freeze @replacement = replacement.freeze @affected_lines_before = affected_lines.freeze end |
Instance Attribute Details
#affected_lines_before ⇒ Object (readonly)
Returns the value of attribute affected_lines_before.
6 7 8 |
# File 'lib/pronto/clang_format/offence.rb', line 6 def affected_lines_before @affected_lines_before end |
#column ⇒ Object (readonly)
Returns the value of attribute column.
6 7 8 |
# File 'lib/pronto/clang_format/offence.rb', line 6 def column @column end |
#length ⇒ Object (readonly)
Returns the value of attribute length.
6 7 8 |
# File 'lib/pronto/clang_format/offence.rb', line 6 def length @length end |
#line_no ⇒ Object (readonly)
Returns the value of attribute line_no.
6 7 8 |
# File 'lib/pronto/clang_format/offence.rb', line 6 def line_no @line_no end |
#offset ⇒ Object (readonly)
Returns the value of attribute offset.
6 7 8 |
# File 'lib/pronto/clang_format/offence.rb', line 6 def offset @offset end |
#replacement ⇒ Object (readonly)
Returns the value of attribute replacement.
6 7 8 |
# File 'lib/pronto/clang_format/offence.rb', line 6 def replacement @replacement end |
Instance Method Details
#affected_lines_after ⇒ Object
returns affected lines after fixing this offence
35 36 37 38 39 |
# File 'lib/pronto/clang_format/offence.rb', line 35 def affected_lines_after affected_lines = String.new(affected_lines_before) affected_lines[column..(column + length - 1)] = replacement affected_lines end |
#affected_lines_range ⇒ Object
returns the range of line numbers affected by this offence
30 31 32 |
# File 'lib/pronto/clang_format/offence.rb', line 30 def affected_lines_range (line_no..line_no + replaced_text.count("\n")) end |
#msg ⇒ Object
generates a user-friendly message that describes this offence. This is done by using OffenceCategorizer’s chain of responsibility classes
20 21 22 |
# File 'lib/pronto/clang_format/offence.rb', line 20 def msg OffenceCategorizer::Factory.create_categorizers.handle self end |
#replaced_text ⇒ Object
the exact portion of text that is to be replaced by this offence
25 26 27 |
# File 'lib/pronto/clang_format/offence.rb', line 25 def replaced_text affected_lines_before[column..(column + length - 1)] end |