Class: Sarif::Node
- Inherits:
-
Object
- Object
- Sarif::Node
- Defined in:
- lib/sarif/node.rb
Overview
Represents a node in a graph.
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#id ⇒ Object
Returns the value of attribute id.
-
#label ⇒ Object
Returns the value of attribute label.
-
#location ⇒ Object
Returns the value of attribute location.
-
#properties ⇒ Object
Returns the value of attribute properties.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(id:, label: nil, location: nil, children: [], properties: nil) ⇒ Node
constructor
A new instance of Node.
- #to_h ⇒ Object
- #to_json(pretty: false) ⇒ Object
Constructor Details
#initialize(id:, label: nil, location: nil, children: [], properties: nil) ⇒ Node
Returns a new instance of Node.
8 9 10 11 12 13 14 |
# File 'lib/sarif/node.rb', line 8 def initialize(id:, label: nil, location: nil, children: [], properties: nil) @id = id @label = label @location = location @children = children @properties = properties end |
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
6 7 8 |
# File 'lib/sarif/node.rb', line 6 def children @children end |
#id ⇒ Object
Returns the value of attribute id.
6 7 8 |
# File 'lib/sarif/node.rb', line 6 def id @id end |
#label ⇒ Object
Returns the value of attribute label.
6 7 8 |
# File 'lib/sarif/node.rb', line 6 def label @label end |
#location ⇒ Object
Returns the value of attribute location.
6 7 8 |
# File 'lib/sarif/node.rb', line 6 def location @location end |
#properties ⇒ Object
Returns the value of attribute properties.
6 7 8 |
# File 'lib/sarif/node.rb', line 6 def properties @properties end |
Class Method Details
.from_hash(h) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/sarif/node.rb', line 30 def self.from_hash(h) return nil if h.nil? new( id: h["id"], label: Message.from_hash(h["label"]), location: Location.from_hash(h["location"]), children: h["children"]&.map { |v| Node.from_hash(v) } || [], properties: h["properties"] ) end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
41 42 43 44 |
# File 'lib/sarif/node.rb', line 41 def ==(other) return false unless other.is_a?(Node) @id == other.id && @label == other.label && @location == other.location && @children == other.children && @properties == other.properties end |
#hash ⇒ Object
48 49 50 |
# File 'lib/sarif/node.rb', line 48 def hash [@id, @label, @location, @children, @properties].hash end |
#to_h ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/sarif/node.rb', line 16 def to_h h = {} h["id"] = @id h["label"] = @label&.to_h unless @label.nil? h["location"] = @location&.to_h unless @location.nil? h["children"] = @children&.map(&:to_h) if @children&.any? h["properties"] = @properties unless @properties.nil? h end |
#to_json(pretty: false) ⇒ Object
26 27 28 |
# File 'lib/sarif/node.rb', line 26 def to_json(pretty: false) pretty ? JSON.pretty_generate(to_h) : JSON.generate(to_h) end |