Class: Pronto::ClangFormat::Offence

Inherits:
Object
  • Object
show all
Defined in:
lib/pronto/clang_format/offence.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_beforeObject (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

#columnObject (readonly)

Returns the value of attribute column.



6
7
8
# File 'lib/pronto/clang_format/offence.rb', line 6

def column
  @column
end

#lengthObject (readonly)

Returns the value of attribute length.



6
7
8
# File 'lib/pronto/clang_format/offence.rb', line 6

def length
  @length
end

#line_noObject (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

#offsetObject (readonly)

Returns the value of attribute offset.



6
7
8
# File 'lib/pronto/clang_format/offence.rb', line 6

def offset
  @offset
end

#replacementObject (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_afterObject

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_rangeObject

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

#msgObject

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_textObject

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