Class: Sarif::Location
- Inherits:
-
Object
- Object
- Sarif::Location
- Defined in:
- lib/sarif/location.rb
Overview
A location within a programming artifact.
Instance Attribute Summary collapse
-
#annotations ⇒ Object
Returns the value of attribute annotations.
-
#id ⇒ Object
Returns the value of attribute id.
-
#logical_locations ⇒ Object
Returns the value of attribute logical_locations.
-
#message ⇒ Object
Returns the value of attribute message.
-
#physical_location ⇒ Object
Returns the value of attribute physical_location.
-
#properties ⇒ Object
Returns the value of attribute properties.
-
#relationships ⇒ Object
Returns the value of attribute relationships.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(id: -1,, physical_location: nil, logical_locations: [], message: nil, annotations: [], relationships: [], properties: nil) ⇒ Location
constructor
A new instance of Location.
- #to_h ⇒ Object
- #to_json(pretty: false) ⇒ Object
Constructor Details
#initialize(id: -1,, physical_location: nil, logical_locations: [], message: nil, annotations: [], relationships: [], properties: nil) ⇒ Location
Returns a new instance of Location.
8 9 10 11 12 13 14 15 16 |
# File 'lib/sarif/location.rb', line 8 def initialize(id: -1, physical_location: nil, logical_locations: [], message: nil, annotations: [], relationships: [], properties: nil) @id = id @physical_location = physical_location @logical_locations = logical_locations @message = @annotations = annotations @relationships = relationships @properties = properties end |
Instance Attribute Details
#annotations ⇒ Object
Returns the value of attribute annotations.
6 7 8 |
# File 'lib/sarif/location.rb', line 6 def annotations @annotations end |
#id ⇒ Object
Returns the value of attribute id.
6 7 8 |
# File 'lib/sarif/location.rb', line 6 def id @id end |
#logical_locations ⇒ Object
Returns the value of attribute logical_locations.
6 7 8 |
# File 'lib/sarif/location.rb', line 6 def logical_locations @logical_locations end |
#message ⇒ Object
Returns the value of attribute message.
6 7 8 |
# File 'lib/sarif/location.rb', line 6 def @message end |
#physical_location ⇒ Object
Returns the value of attribute physical_location.
6 7 8 |
# File 'lib/sarif/location.rb', line 6 def physical_location @physical_location end |
#properties ⇒ Object
Returns the value of attribute properties.
6 7 8 |
# File 'lib/sarif/location.rb', line 6 def properties @properties end |
#relationships ⇒ Object
Returns the value of attribute relationships.
6 7 8 |
# File 'lib/sarif/location.rb', line 6 def relationships @relationships end |
Class Method Details
.from_hash(h) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/sarif/location.rb', line 34 def self.from_hash(h) return nil if h.nil? new( id: h["id"] || -1, physical_location: PhysicalLocation.from_hash(h["physicalLocation"]), logical_locations: h["logicalLocations"]&.map { |v| LogicalLocation.from_hash(v) } || [], message: Message.from_hash(h["message"]), annotations: h["annotations"]&.map { |v| Region.from_hash(v) } || [], relationships: h["relationships"]&.map { |v| LocationRelationship.from_hash(v) } || [], properties: h["properties"] ) end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
47 48 49 50 |
# File 'lib/sarif/location.rb', line 47 def ==(other) return false unless other.is_a?(Location) @id == other.id && @physical_location == other.physical_location && @logical_locations == other.logical_locations && @message == other. && @annotations == other.annotations && @relationships == other.relationships && @properties == other.properties end |
#hash ⇒ Object
54 55 56 |
# File 'lib/sarif/location.rb', line 54 def hash [@id, @physical_location, @logical_locations, @message, @annotations, @relationships, @properties].hash end |
#to_h ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/sarif/location.rb', line 18 def to_h h = {} h["id"] = @id if @id && @id != -1 h["physicalLocation"] = @physical_location&.to_h unless @physical_location.nil? h["logicalLocations"] = @logical_locations&.map(&:to_h) if @logical_locations&.any? h["message"] = @message&.to_h unless @message.nil? h["annotations"] = @annotations&.map(&:to_h) if @annotations&.any? h["relationships"] = @relationships&.map(&:to_h) if @relationships&.any? h["properties"] = @properties unless @properties.nil? h end |
#to_json(pretty: false) ⇒ Object
30 31 32 |
# File 'lib/sarif/location.rb', line 30 def to_json(pretty: false) pretty ? JSON.pretty_generate(to_h) : JSON.generate(to_h) end |