Class: Sarif::Attachment

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

Overview

An artifact relevant to a result.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(description: nil, artifact_location:, regions: [], rectangles: [], properties: nil) ⇒ Attachment

Returns a new instance of Attachment.



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

def initialize(description: nil, artifact_location:, regions: [], rectangles: [], properties: nil)
  @description = description
  @artifact_location = artifact_location
  @regions = regions
  @rectangles = rectangles
  @properties = properties
end

Instance Attribute Details

#artifact_locationObject

Returns the value of attribute artifact_location.



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

def artifact_location
  @artifact_location
end

#descriptionObject

Returns the value of attribute description.



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

def description
  @description
end

#propertiesObject

Returns the value of attribute properties.



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

def properties
  @properties
end

#rectanglesObject

Returns the value of attribute rectangles.



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

def rectangles
  @rectangles
end

#regionsObject

Returns the value of attribute regions.



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

def regions
  @regions
end

Class Method Details

.from_hash(h) ⇒ Object



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

def self.from_hash(h)
  return nil if h.nil?
  new(
    description: Message.from_hash(h["description"]),
    artifact_location: ArtifactLocation.from_hash(h["artifactLocation"]),
    regions: h["regions"]&.map { |v| Region.from_hash(v) } || [],
    rectangles: h["rectangles"]&.map { |v| Rectangle.from_hash(v) } || [],
    properties: h["properties"]
  )
end

Instance Method Details

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



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

def ==(other)
  return false unless other.is_a?(Attachment)
  @description == other.description && @artifact_location == other.artifact_location && @regions == other.regions && @rectangles == other.rectangles && @properties == other.properties
end

#hashObject



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

def hash
  [@description, @artifact_location, @regions, @rectangles, @properties].hash
end

#to_hObject



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

def to_h
  h = {}
  h["description"] = @description&.to_h unless @description.nil?
  h["artifactLocation"] = @artifact_location&.to_h
  h["regions"] = @regions&.map(&:to_h) if @regions&.any?
  h["rectangles"] = @rectangles&.map(&:to_h) if @rectangles&.any?
  h["properties"] = @properties unless @properties.nil?
  h
end

#to_json(pretty: false) ⇒ Object



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

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