Class: Sarif::GraphTraversal

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

Overview

Represents a path through a graph.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(run_graph_index: -1,, result_graph_index: -1,, description: nil, initial_state: nil, immutable_state: nil, edge_traversals: [], properties: nil) ⇒ GraphTraversal

Returns a new instance of GraphTraversal.



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

def initialize(run_graph_index: -1, result_graph_index: -1, description: nil, initial_state: nil, immutable_state: nil, edge_traversals: [], properties: nil)
  @run_graph_index = run_graph_index
  @result_graph_index = result_graph_index
  @description = description
  @initial_state = initial_state
  @immutable_state = immutable_state
  @edge_traversals = edge_traversals
  @properties = properties
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



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

def description
  @description
end

#edge_traversalsObject

Returns the value of attribute edge_traversals.



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

def edge_traversals
  @edge_traversals
end

#immutable_stateObject

Returns the value of attribute immutable_state.



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

def immutable_state
  @immutable_state
end

#initial_stateObject

Returns the value of attribute initial_state.



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

def initial_state
  @initial_state
end

#propertiesObject

Returns the value of attribute properties.



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

def properties
  @properties
end

#result_graph_indexObject

Returns the value of attribute result_graph_index.



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

def result_graph_index
  @result_graph_index
end

#run_graph_indexObject

Returns the value of attribute run_graph_index.



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

def run_graph_index
  @run_graph_index
end

Class Method Details

.from_hash(h) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/sarif/graph_traversal.rb', line 34

def self.from_hash(h)
  return nil if h.nil?
  new(
    run_graph_index: h["runGraphIndex"] || -1,
    result_graph_index: h["resultGraphIndex"] || -1,
    description: Message.from_hash(h["description"]),
    initial_state: h["initialState"],
    immutable_state: h["immutableState"],
    edge_traversals: h["edgeTraversals"]&.map { |v| EdgeTraversal.from_hash(v) } || [],
    properties: h["properties"]
  )
end

Instance Method Details

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



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

def ==(other)
  return false unless other.is_a?(GraphTraversal)
  @run_graph_index == other.run_graph_index && @result_graph_index == other.result_graph_index && @description == other.description && @initial_state == other.initial_state && @immutable_state == other.immutable_state && @edge_traversals == other.edge_traversals && @properties == other.properties
end

#hashObject



54
55
56
# File 'lib/sarif/graph_traversal.rb', line 54

def hash
  [@run_graph_index, @result_graph_index, @description, @initial_state, @immutable_state, @edge_traversals, @properties].hash
end

#to_hObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/sarif/graph_traversal.rb', line 18

def to_h
  h = {}
  h["runGraphIndex"] = @run_graph_index if @run_graph_index && @run_graph_index != -1
  h["resultGraphIndex"] = @result_graph_index if @result_graph_index && @result_graph_index != -1
  h["description"] = @description&.to_h unless @description.nil?
  h["initialState"] = @initial_state unless @initial_state.nil?
  h["immutableState"] = @immutable_state unless @immutable_state.nil?
  h["edgeTraversals"] = @edge_traversals&.map(&:to_h) if @edge_traversals&.any?
  h["properties"] = @properties unless @properties.nil?
  h
end

#to_json(pretty: false) ⇒ Object



30
31
32
# File 'lib/sarif/graph_traversal.rb', line 30

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