Class: JSON5::Diagnostic

Inherits:
Object
  • Object
show all
Defined in:
lib/json5/diagnostic.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code:, message:, severity: :warning, filename: nil, byte_offset: nil, end_byte_offset: nil, line: nil, column: nil) ⇒ Diagnostic

Returns a new instance of Diagnostic.



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/json5/diagnostic.rb', line 8

def initialize(code:, message:, severity: :warning, filename: nil,
               byte_offset: nil, end_byte_offset: nil, line: nil,
               column: nil)
  @severity = severity.to_sym
  @code = code.to_s.dup.freeze
  @message = message.to_s.dup.freeze
  @filename = filename.nil? ? nil : filename.to_s.dup.freeze
  @byte_offset = byte_offset
  @end_byte_offset = end_byte_offset
  @line = line
  @column = column
  freeze
end

Instance Attribute Details

#byte_offsetObject (readonly)

Returns the value of attribute byte_offset.



5
6
7
# File 'lib/json5/diagnostic.rb', line 5

def byte_offset
  @byte_offset
end

#codeObject (readonly)

Returns the value of attribute code.



5
6
7
# File 'lib/json5/diagnostic.rb', line 5

def code
  @code
end

#columnObject (readonly)

Returns the value of attribute column.



5
6
7
# File 'lib/json5/diagnostic.rb', line 5

def column
  @column
end

#end_byte_offsetObject (readonly)

Returns the value of attribute end_byte_offset.



5
6
7
# File 'lib/json5/diagnostic.rb', line 5

def end_byte_offset
  @end_byte_offset
end

#filenameObject (readonly)

Returns the value of attribute filename.



5
6
7
# File 'lib/json5/diagnostic.rb', line 5

def filename
  @filename
end

#lineObject (readonly)

Returns the value of attribute line.



5
6
7
# File 'lib/json5/diagnostic.rb', line 5

def line
  @line
end

#messageObject (readonly)

Returns the value of attribute message.



5
6
7
# File 'lib/json5/diagnostic.rb', line 5

def message
  @message
end

#severityObject (readonly)

Returns the value of attribute severity.



5
6
7
# File 'lib/json5/diagnostic.rb', line 5

def severity
  @severity
end

Instance Method Details

#to_hObject



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/json5/diagnostic.rb', line 22

def to_h
  {
    severity: severity,
    code: code,
    message: message,
    filename: filename,
    byte_offset: byte_offset,
    end_byte_offset: end_byte_offset,
    line: line,
    column: column
  }
end