Class: Sarif::Attachment
- Inherits:
-
Object
- Object
- Sarif::Attachment
- Defined in:
- lib/sarif/attachment.rb
Overview
An artifact relevant to a result.
Instance Attribute Summary collapse
-
#artifact_location ⇒ Object
Returns the value of attribute artifact_location.
-
#description ⇒ Object
Returns the value of attribute description.
-
#properties ⇒ Object
Returns the value of attribute properties.
-
#rectangles ⇒ Object
Returns the value of attribute rectangles.
-
#regions ⇒ Object
Returns the value of attribute regions.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(description: nil, artifact_location:, regions: [], rectangles: [], properties: nil) ⇒ Attachment
constructor
A new instance of Attachment.
- #to_h ⇒ Object
- #to_json(pretty: false) ⇒ Object
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_location ⇒ Object
Returns the value of attribute artifact_location.
6 7 8 |
# File 'lib/sarif/attachment.rb', line 6 def artifact_location @artifact_location end |
#description ⇒ Object
Returns the value of attribute description.
6 7 8 |
# File 'lib/sarif/attachment.rb', line 6 def description @description end |
#properties ⇒ Object
Returns the value of attribute properties.
6 7 8 |
# File 'lib/sarif/attachment.rb', line 6 def properties @properties end |
#rectangles ⇒ Object
Returns the value of attribute rectangles.
6 7 8 |
# File 'lib/sarif/attachment.rb', line 6 def rectangles @rectangles end |
#regions ⇒ Object
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 |
#hash ⇒ Object
48 49 50 |
# File 'lib/sarif/attachment.rb', line 48 def hash [@description, @artifact_location, @regions, @rectangles, @properties].hash end |
#to_h ⇒ Object
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 |