Class: Sarif::Region

Inherits:
Object
  • Object
show all
Defined in:
lib/sarif/region.rb

Overview

A region within an artifact where a result was detected.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start_line: nil, start_column: nil, end_line: nil, end_column: nil, char_offset: -1,, char_length: nil, byte_offset: -1,, byte_length: nil, snippet: nil, message: nil, source_language: nil, properties: nil) ⇒ Region

Returns a new instance of Region.



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

def initialize(start_line: nil, start_column: nil, end_line: nil, end_column: nil, char_offset: -1, char_length: nil, byte_offset: -1, byte_length: nil, snippet: nil, message: nil, source_language: nil, properties: nil)
  @start_line = start_line
  @start_column = start_column
  @end_line = end_line
  @end_column = end_column
  @char_offset = char_offset
  @char_length = char_length
  @byte_offset = byte_offset
  @byte_length = byte_length
  @snippet = snippet
  @message = message
  @source_language = source_language
  @properties = properties
end

Instance Attribute Details

#byte_lengthObject

Returns the value of attribute byte_length.



6
7
8
# File 'lib/sarif/region.rb', line 6

def byte_length
  @byte_length
end

#byte_offsetObject

Returns the value of attribute byte_offset.



6
7
8
# File 'lib/sarif/region.rb', line 6

def byte_offset
  @byte_offset
end

#char_lengthObject

Returns the value of attribute char_length.



6
7
8
# File 'lib/sarif/region.rb', line 6

def char_length
  @char_length
end

#char_offsetObject

Returns the value of attribute char_offset.



6
7
8
# File 'lib/sarif/region.rb', line 6

def char_offset
  @char_offset
end

#end_columnObject

Returns the value of attribute end_column.



6
7
8
# File 'lib/sarif/region.rb', line 6

def end_column
  @end_column
end

#end_lineObject

Returns the value of attribute end_line.



6
7
8
# File 'lib/sarif/region.rb', line 6

def end_line
  @end_line
end

#messageObject

Returns the value of attribute message.



6
7
8
# File 'lib/sarif/region.rb', line 6

def message
  @message
end

#propertiesObject

Returns the value of attribute properties.



6
7
8
# File 'lib/sarif/region.rb', line 6

def properties
  @properties
end

#snippetObject

Returns the value of attribute snippet.



6
7
8
# File 'lib/sarif/region.rb', line 6

def snippet
  @snippet
end

#source_languageObject

Returns the value of attribute source_language.



6
7
8
# File 'lib/sarif/region.rb', line 6

def source_language
  @source_language
end

#start_columnObject

Returns the value of attribute start_column.



6
7
8
# File 'lib/sarif/region.rb', line 6

def start_column
  @start_column
end

#start_lineObject

Returns the value of attribute start_line.



6
7
8
# File 'lib/sarif/region.rb', line 6

def start_line
  @start_line
end

Class Method Details

.from_hash(h) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/sarif/region.rb', line 44

def self.from_hash(h)
  return nil if h.nil?
  new(
    start_line: h["startLine"],
    start_column: h["startColumn"],
    end_line: h["endLine"],
    end_column: h["endColumn"],
    char_offset: h["charOffset"] || -1,
    char_length: h["charLength"],
    byte_offset: h["byteOffset"] || -1,
    byte_length: h["byteLength"],
    snippet: ArtifactContent.from_hash(h["snippet"]),
    message: Message.from_hash(h["message"]),
    source_language: h["sourceLanguage"],
    properties: h["properties"]
  )
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



62
63
64
65
# File 'lib/sarif/region.rb', line 62

def ==(other)
  return false unless other.is_a?(Region)
  @start_line == other.start_line && @start_column == other.start_column && @end_line == other.end_line && @end_column == other.end_column && @char_offset == other.char_offset && @char_length == other.char_length && @byte_offset == other.byte_offset && @byte_length == other.byte_length && @snippet == other.snippet && @message == other.message && @source_language == other.source_language && @properties == other.properties
end

#hashObject



69
70
71
# File 'lib/sarif/region.rb', line 69

def hash
  [@start_line, @start_column, @end_line, @end_column, @char_offset, @char_length, @byte_offset, @byte_length, @snippet, @message, @source_language, @properties].hash
end

#to_hObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/sarif/region.rb', line 23

def to_h
  h = {}
  h["startLine"] = @start_line unless @start_line.nil?
  h["startColumn"] = @start_column unless @start_column.nil?
  h["endLine"] = @end_line unless @end_line.nil?
  h["endColumn"] = @end_column unless @end_column.nil?
  h["charOffset"] = @char_offset if @char_offset && @char_offset != -1
  h["charLength"] = @char_length unless @char_length.nil?
  h["byteOffset"] = @byte_offset if @byte_offset && @byte_offset != -1
  h["byteLength"] = @byte_length unless @byte_length.nil?
  h["snippet"] = @snippet&.to_h unless @snippet.nil?
  h["message"] = @message&.to_h unless @message.nil?
  h["sourceLanguage"] = @source_language unless @source_language.nil?
  h["properties"] = @properties unless @properties.nil?
  h
end

#to_json(pretty: false) ⇒ Object



40
41
42
# File 'lib/sarif/region.rb', line 40

def to_json(pretty: false)
  pretty ? JSON.pretty_generate(to_h) : JSON.generate(to_h)
end