Class: Sarif::ArtifactContent

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

Overview

Represents the contents of an artifact.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text: nil, binary: nil, rendered: nil, properties: nil) ⇒ ArtifactContent

Returns a new instance of ArtifactContent.



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

def initialize(text: nil, binary: nil, rendered: nil, properties: nil)
  @text = text
  @binary = binary
  @rendered = rendered
  @properties = properties
end

Instance Attribute Details

#binaryObject

Returns the value of attribute binary.



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

def binary
  @binary
end

#propertiesObject

Returns the value of attribute properties.



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

def properties
  @properties
end

#renderedObject

Returns the value of attribute rendered.



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

def rendered
  @rendered
end

#textObject

Returns the value of attribute text.



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

def text
  @text
end

Class Method Details

.from_hash(h) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/sarif/artifact_content.rb', line 28

def self.from_hash(h)
  return nil if h.nil?
  new(
    text: h["text"],
    binary: h["binary"],
    rendered: MultiformatMessageString.from_hash(h["rendered"]),
    properties: h["properties"]
  )
end

Instance Method Details

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



38
39
40
41
# File 'lib/sarif/artifact_content.rb', line 38

def ==(other)
  return false unless other.is_a?(ArtifactContent)
  @text == other.text && @binary == other.binary && @rendered == other.rendered && @properties == other.properties
end

#hashObject



45
46
47
# File 'lib/sarif/artifact_content.rb', line 45

def hash
  [@text, @binary, @rendered, @properties].hash
end

#to_hObject



15
16
17
18
19
20
21
22
# File 'lib/sarif/artifact_content.rb', line 15

def to_h
  h = {}
  h["text"] = @text unless @text.nil?
  h["binary"] = @binary unless @binary.nil?
  h["rendered"] = @rendered&.to_h unless @rendered.nil?
  h["properties"] = @properties unless @properties.nil?
  h
end

#to_json(pretty: false) ⇒ Object



24
25
26
# File 'lib/sarif/artifact_content.rb', line 24

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