Class: Sarif::Edge

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

Overview

Represents a directed edge in a graph.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, label: nil, source_node_id:, target_node_id:, properties: nil) ⇒ Edge

Returns a new instance of Edge.



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

def initialize(id:, label: nil, source_node_id:, target_node_id:, properties: nil)
  @id = id
  @label = label
  @source_node_id = source_node_id
  @target_node_id = target_node_id
  @properties = properties
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#labelObject

Returns the value of attribute label.



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

def label
  @label
end

#propertiesObject

Returns the value of attribute properties.



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

def properties
  @properties
end

#source_node_idObject

Returns the value of attribute source_node_id.



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

def source_node_id
  @source_node_id
end

#target_node_idObject

Returns the value of attribute target_node_id.



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

def target_node_id
  @target_node_id
end

Class Method Details

.from_hash(h) ⇒ Object



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

def self.from_hash(h)
  return nil if h.nil?
  new(
    id: h["id"],
    label: Message.from_hash(h["label"]),
    source_node_id: h["sourceNodeId"],
    target_node_id: h["targetNodeId"],
    properties: h["properties"]
  )
end

Instance Method Details

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



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

def ==(other)
  return false unless other.is_a?(Edge)
  @id == other.id && @label == other.label && @source_node_id == other.source_node_id && @target_node_id == other.target_node_id && @properties == other.properties
end

#hashObject



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

def hash
  [@id, @label, @source_node_id, @target_node_id, @properties].hash
end

#to_hObject



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

def to_h
  h = {}
  h["id"] = @id
  h["label"] = @label&.to_h unless @label.nil?
  h["sourceNodeId"] = @source_node_id
  h["targetNodeId"] = @target_node_id
  h["properties"] = @properties unless @properties.nil?
  h
end

#to_json(pretty: false) ⇒ Object



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

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