Class: Sarif::Edge
- Inherits:
-
Object
- Object
- Sarif::Edge
- Defined in:
- lib/sarif/edge.rb
Overview
Represents a directed edge in a graph.
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#label ⇒ Object
Returns the value of attribute label.
-
#properties ⇒ Object
Returns the value of attribute properties.
-
#source_node_id ⇒ Object
Returns the value of attribute source_node_id.
-
#target_node_id ⇒ Object
Returns the value of attribute target_node_id.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(id:, label: nil, source_node_id:, target_node_id:, properties: nil) ⇒ Edge
constructor
A new instance of Edge.
- #to_h ⇒ Object
- #to_json(pretty: false) ⇒ Object
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
#id ⇒ Object
Returns the value of attribute id.
6 7 8 |
# File 'lib/sarif/edge.rb', line 6 def id @id end |
#label ⇒ Object
Returns the value of attribute label.
6 7 8 |
# File 'lib/sarif/edge.rb', line 6 def label @label end |
#properties ⇒ Object
Returns the value of attribute properties.
6 7 8 |
# File 'lib/sarif/edge.rb', line 6 def properties @properties end |
#source_node_id ⇒ Object
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_id ⇒ Object
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
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 |
#hash ⇒ Object
48 49 50 |
# File 'lib/sarif/edge.rb', line 48 def hash [@id, @label, @source_node_id, @target_node_id, @properties].hash end |
#to_h ⇒ Object
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 |