Class: ERBLint::CachedOffense

Inherits:
Object
  • Object
show all
Defined in:
lib/erb_lint/cached_offense.rb

Overview

A Cached version of an Offense with only essential information represented as strings

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ CachedOffense

Returns a new instance of CachedOffense.



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/erb_lint/cached_offense.rb', line 17

def initialize(params)
  params = params.transform_keys(&:to_sym)

  @message = params[:message]
  @line_number = params[:line_number]
  @severity = params[:severity]&.to_sym
  @column = params[:column]
  @simple_name = params[:simple_name]
  @last_line = params[:last_line]
  @last_column = params[:last_column]
  @length = params[:length]
end

Instance Attribute Details

#columnObject (readonly)

Returns the value of attribute column.



6
7
8
# File 'lib/erb_lint/cached_offense.rb', line 6

def column
  @column
end

#last_columnObject (readonly)

Returns the value of attribute last_column.



6
7
8
# File 'lib/erb_lint/cached_offense.rb', line 6

def last_column
  @last_column
end

#last_lineObject (readonly)

Returns the value of attribute last_line.



6
7
8
# File 'lib/erb_lint/cached_offense.rb', line 6

def last_line
  @last_line
end

#line_numberObject (readonly)

Returns the value of attribute line_number.



6
7
8
# File 'lib/erb_lint/cached_offense.rb', line 6

def line_number
  @line_number
end

#messageObject (readonly)

Returns the value of attribute message.



6
7
8
# File 'lib/erb_lint/cached_offense.rb', line 6

def message
  @message
end

#severityObject (readonly)

Returns the value of attribute severity.



6
7
8
# File 'lib/erb_lint/cached_offense.rb', line 6

def severity
  @severity
end

#simple_nameObject (readonly)

Returns the value of attribute simple_name.



6
7
8
# File 'lib/erb_lint/cached_offense.rb', line 6

def simple_name
  @simple_name
end

Class Method Details

.new_from_offense(offense) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/erb_lint/cached_offense.rb', line 30

def self.new_from_offense(offense)
  new(
    {
      message: offense.message,
      line_number: offense.line_number,
      severity: offense.severity,
      column: offense.column,
      simple_name: offense.simple_name,
      last_line: offense.last_line,
      last_column: offense.last_column,
      length: offense.length,
    },
  )
end

Instance Method Details

#to_hObject



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/erb_lint/cached_offense.rb', line 45

def to_h
  {
    message: message,
    line_number: line_number,
    severity: severity,
    column: column,
    simple_name: simple_name,
    last_line: last_line,
    last_column: last_column,
    length: length,
  }
end