Class: Sarif::Replacement

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

Overview

The replacement of a single region of an artifact.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(deleted_region:, inserted_content: nil, properties: nil) ⇒ Replacement

Returns a new instance of Replacement.



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

def initialize(deleted_region:, inserted_content: nil, properties: nil)
  @deleted_region = deleted_region
  @inserted_content = inserted_content
  @properties = properties
end

Instance Attribute Details

#deleted_regionObject

Returns the value of attribute deleted_region.



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

def deleted_region
  @deleted_region
end

#inserted_contentObject

Returns the value of attribute inserted_content.



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

def inserted_content
  @inserted_content
end

#propertiesObject

Returns the value of attribute properties.



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

def properties
  @properties
end

Class Method Details

.from_hash(h) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/sarif/replacement.rb', line 26

def self.from_hash(h)
  return nil if h.nil?
  new(
    deleted_region: Region.from_hash(h["deletedRegion"]),
    inserted_content: ArtifactContent.from_hash(h["insertedContent"]),
    properties: h["properties"]
  )
end

Instance Method Details

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



35
36
37
38
# File 'lib/sarif/replacement.rb', line 35

def ==(other)
  return false unless other.is_a?(Replacement)
  @deleted_region == other.deleted_region && @inserted_content == other.inserted_content && @properties == other.properties
end

#hashObject



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

def hash
  [@deleted_region, @inserted_content, @properties].hash
end

#to_hObject



14
15
16
17
18
19
20
# File 'lib/sarif/replacement.rb', line 14

def to_h
  h = {}
  h["deletedRegion"] = @deleted_region&.to_h
  h["insertedContent"] = @inserted_content&.to_h unless @inserted_content.nil?
  h["properties"] = @properties unless @properties.nil?
  h
end

#to_json(pretty: false) ⇒ Object



22
23
24
# File 'lib/sarif/replacement.rb', line 22

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