Class: Sarif::Artifact

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

Overview

A single artifact. In some cases, this artifact might be nested within another artifact.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(description: nil, location: nil, parent_index: -1,, offset: nil, length: -1,, roles: [], mime_type: nil, contents: nil, encoding: nil, source_language: nil, hashes: nil, last_modified_time_utc: nil, properties: nil) ⇒ Artifact

Returns a new instance of Artifact.



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

def initialize(description: nil, location: nil, parent_index: -1, offset: nil, length: -1, roles: [], mime_type: nil, contents: nil, encoding: nil, source_language: nil, hashes: nil, last_modified_time_utc: nil, properties: nil)
  @description = description
  @location = location
  @parent_index = parent_index
  @offset = offset
  @length = length
  @roles = roles
  @mime_type = mime_type
  @contents = contents
  @encoding = encoding
  @source_language = source_language
  @hashes = hashes
  @last_modified_time_utc = last_modified_time_utc
  @properties = properties
end

Instance Attribute Details

#contentsObject

Returns the value of attribute contents.



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

def contents
  @contents
end

#descriptionObject

Returns the value of attribute description.



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

def description
  @description
end

#encodingObject

Returns the value of attribute encoding.



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

def encoding
  @encoding
end

#hashesObject

Returns the value of attribute hashes.



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

def hashes
  @hashes
end

#last_modified_time_utcObject

Returns the value of attribute last_modified_time_utc.



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

def last_modified_time_utc
  @last_modified_time_utc
end

#lengthObject

Returns the value of attribute length.



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

def length
  @length
end

#locationObject

Returns the value of attribute location.



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

def location
  @location
end

#mime_typeObject

Returns the value of attribute mime_type.



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

def mime_type
  @mime_type
end

#offsetObject

Returns the value of attribute offset.



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

def offset
  @offset
end

#parent_indexObject

Returns the value of attribute parent_index.



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

def parent_index
  @parent_index
end

#propertiesObject

Returns the value of attribute properties.



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

def properties
  @properties
end

#rolesObject

Returns the value of attribute roles.



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

def roles
  @roles
end

#source_languageObject

Returns the value of attribute source_language.



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

def source_language
  @source_language
end

Class Method Details

.from_hash(h) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/sarif/artifact.rb', line 46

def self.from_hash(h)
  return nil if h.nil?
  new(
    description: Message.from_hash(h["description"]),
    location: ArtifactLocation.from_hash(h["location"]),
    parent_index: h["parentIndex"] || -1,
    offset: h["offset"],
    length: h["length"] || -1,
    roles: h["roles"] || [],
    mime_type: h["mimeType"],
    contents: ArtifactContent.from_hash(h["contents"]),
    encoding: h["encoding"],
    source_language: h["sourceLanguage"],
    hashes: h["hashes"],
    last_modified_time_utc: h["lastModifiedTimeUtc"],
    properties: h["properties"]
  )
end

Instance Method Details

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



65
66
67
68
# File 'lib/sarif/artifact.rb', line 65

def ==(other)
  return false unless other.is_a?(Artifact)
  @description == other.description && @location == other.location && @parent_index == other.parent_index && @offset == other.offset && @length == other.length && @roles == other.roles && @mime_type == other.mime_type && @contents == other.contents && @encoding == other.encoding && @source_language == other.source_language && @hashes == other.hashes && @last_modified_time_utc == other.last_modified_time_utc && @properties == other.properties
end

#hashObject



72
73
74
# File 'lib/sarif/artifact.rb', line 72

def hash
  [@description, @location, @parent_index, @offset, @length, @roles, @mime_type, @contents, @encoding, @source_language, @hashes, @last_modified_time_utc, @properties].hash
end

#to_hObject



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

def to_h
  h = {}
  h["description"] = @description&.to_h unless @description.nil?
  h["location"] = @location&.to_h unless @location.nil?
  h["parentIndex"] = @parent_index if @parent_index && @parent_index != -1
  h["offset"] = @offset unless @offset.nil?
  h["length"] = @length if @length && @length != -1
  h["roles"] = @roles&.map(&:to_s) if @roles&.any?
  h["mimeType"] = @mime_type unless @mime_type.nil?
  h["contents"] = @contents&.to_h unless @contents.nil?
  h["encoding"] = @encoding unless @encoding.nil?
  h["sourceLanguage"] = @source_language unless @source_language.nil?
  h["hashes"] = @hashes unless @hashes.nil?
  h["lastModifiedTimeUtc"] = @last_modified_time_utc unless @last_modified_time_utc.nil?
  h["properties"] = @properties unless @properties.nil?
  h
end

#to_json(pretty: false) ⇒ Object



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

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