Class: OffenseToCorrector::Offense
- Inherits:
-
Object
- Object
- OffenseToCorrector::Offense
- Defined in:
- lib/offense_to_corrector/offense.rb
Constant Summary collapse
- OFFENSE_MATCH =
How many underline carots (^), and potentially an error after
/^ *?(?<underline>\^+) *?(?<error>.*)?$/
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#range ⇒ Object
readonly
Returns the value of attribute range.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Class Method Summary collapse
-
.parse(line:, previous_line:) ⇒ Object
See if there’s an underline, if so get how long it is and the error message after it.
Instance Method Summary collapse
- #deconstruct_keys(keys) ⇒ Object
-
#initialize(error:, range:, source:) ⇒ Offense
constructor
A new instance of Offense.
Constructor Details
#initialize(error:, range:, source:) ⇒ Offense
Returns a new instance of Offense.
8 9 10 11 12 |
# File 'lib/offense_to_corrector/offense.rb', line 8 def initialize(error:, range:, source:) @error = error @range = range @source = source end |
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the value of attribute error.
6 7 8 |
# File 'lib/offense_to_corrector/offense.rb', line 6 def error @error end |
#range ⇒ Object (readonly)
Returns the value of attribute range.
6 7 8 |
# File 'lib/offense_to_corrector/offense.rb', line 6 def range @range end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
6 7 8 |
# File 'lib/offense_to_corrector/offense.rb', line 6 def source @source end |
Class Method Details
.parse(line:, previous_line:) ⇒ Object
See if there’s an underline, if so get how long it is and the error message after it
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/offense_to_corrector/offense.rb', line 21 def self.parse(line:, previous_line:) match_data = OFFENSE_MATCH.match(line) or return nil underline = match_data[:underline] error = match_data[:error].lstrip underline_start = line.index(underline) underline_end = underline_start + underline.size range = underline_start...underline_end source = previous_line.slice(range).chomp new(error:, range:, source:) end |
Instance Method Details
#deconstruct_keys(keys) ⇒ Object
14 15 16 |
# File 'lib/offense_to_corrector/offense.rb', line 14 def deconstruct_keys(keys) { error:, range:, source: } end |