Class: Sarif::Location

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

Overview

A location within a programming artifact.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id: -1,, physical_location: nil, logical_locations: [], message: nil, annotations: [], relationships: [], properties: nil) ⇒ Location

Returns a new instance of Location.



8
9
10
11
12
13
14
15
16
# File 'lib/sarif/location.rb', line 8

def initialize(id: -1, physical_location: nil, logical_locations: [], message: nil, annotations: [], relationships: [], properties: nil)
  @id = id
  @physical_location = physical_location
  @logical_locations = logical_locations
  @message = message
  @annotations = annotations
  @relationships = relationships
  @properties = properties
end

Instance Attribute Details

#annotationsObject

Returns the value of attribute annotations.



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

def annotations
  @annotations
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#logical_locationsObject

Returns the value of attribute logical_locations.



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

def logical_locations
  @logical_locations
end

#messageObject

Returns the value of attribute message.



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

def message
  @message
end

#physical_locationObject

Returns the value of attribute physical_location.



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

def physical_location
  @physical_location
end

#propertiesObject

Returns the value of attribute properties.



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

def properties
  @properties
end

#relationshipsObject

Returns the value of attribute relationships.



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

def relationships
  @relationships
end

Class Method Details

.from_hash(h) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/sarif/location.rb', line 34

def self.from_hash(h)
  return nil if h.nil?
  new(
    id: h["id"] || -1,
    physical_location: PhysicalLocation.from_hash(h["physicalLocation"]),
    logical_locations: h["logicalLocations"]&.map { |v| LogicalLocation.from_hash(v) } || [],
    message: Message.from_hash(h["message"]),
    annotations: h["annotations"]&.map { |v| Region.from_hash(v) } || [],
    relationships: h["relationships"]&.map { |v| LocationRelationship.from_hash(v) } || [],
    properties: h["properties"]
  )
end

Instance Method Details

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



47
48
49
50
# File 'lib/sarif/location.rb', line 47

def ==(other)
  return false unless other.is_a?(Location)
  @id == other.id && @physical_location == other.physical_location && @logical_locations == other.logical_locations && @message == other.message && @annotations == other.annotations && @relationships == other.relationships && @properties == other.properties
end

#hashObject



54
55
56
# File 'lib/sarif/location.rb', line 54

def hash
  [@id, @physical_location, @logical_locations, @message, @annotations, @relationships, @properties].hash
end

#to_hObject



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

def to_h
  h = {}
  h["id"] = @id if @id && @id != -1
  h["physicalLocation"] = @physical_location&.to_h unless @physical_location.nil?
  h["logicalLocations"] = @logical_locations&.map(&:to_h) if @logical_locations&.any?
  h["message"] = @message&.to_h unless @message.nil?
  h["annotations"] = @annotations&.map(&:to_h) if @annotations&.any?
  h["relationships"] = @relationships&.map(&:to_h) if @relationships&.any?
  h["properties"] = @properties unless @properties.nil?
  h
end

#to_json(pretty: false) ⇒ Object



30
31
32
# File 'lib/sarif/location.rb', line 30

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