Class: Sarif::PhysicalLocation

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

Overview

A physical location relevant to a result. Specifies a reference to a programming artifact together with a range of bytes or characters within that artifact.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(address: nil, artifact_location: nil, region: nil, context_region: nil, properties: nil) ⇒ PhysicalLocation

Returns a new instance of PhysicalLocation.



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

def initialize(address: nil, artifact_location: nil, region: nil, context_region: nil, properties: nil)
  @address = address
  @artifact_location = artifact_location
  @region = region
  @context_region = context_region
  @properties = properties
end

Instance Attribute Details

#addressObject

Returns the value of attribute address.



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

def address
  @address
end

#artifact_locationObject

Returns the value of attribute artifact_location.



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

def artifact_location
  @artifact_location
end

#context_regionObject

Returns the value of attribute context_region.



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

def context_region
  @context_region
end

#propertiesObject

Returns the value of attribute properties.



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

def properties
  @properties
end

#regionObject

Returns the value of attribute region.



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

def region
  @region
end

Class Method Details

.from_hash(h) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/sarif/physical_location.rb', line 30

def self.from_hash(h)
  return nil if h.nil?
  new(
    address: Address.from_hash(h["address"]),
    artifact_location: ArtifactLocation.from_hash(h["artifactLocation"]),
    region: Region.from_hash(h["region"]),
    context_region: Region.from_hash(h["contextRegion"]),
    properties: h["properties"]
  )
end

Instance Method Details

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



41
42
43
44
# File 'lib/sarif/physical_location.rb', line 41

def ==(other)
  return false unless other.is_a?(PhysicalLocation)
  @address == other.address && @artifact_location == other.artifact_location && @region == other.region && @context_region == other.context_region && @properties == other.properties
end

#hashObject



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

def hash
  [@address, @artifact_location, @region, @context_region, @properties].hash
end

#to_hObject



16
17
18
19
20
21
22
23
24
# File 'lib/sarif/physical_location.rb', line 16

def to_h
  h = {}
  h["address"] = @address&.to_h unless @address.nil?
  h["artifactLocation"] = @artifact_location&.to_h unless @artifact_location.nil?
  h["region"] = @region&.to_h unless @region.nil?
  h["contextRegion"] = @context_region&.to_h unless @context_region.nil?
  h["properties"] = @properties unless @properties.nil?
  h
end

#to_json(pretty: false) ⇒ Object



26
27
28
# File 'lib/sarif/physical_location.rb', line 26

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