Class: Sarif::PropertyBag

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

Overview

Key/value pairs that provide additional information about the object.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tags: []) ⇒ PropertyBag

Returns a new instance of PropertyBag.



8
9
10
# File 'lib/sarif/property_bag.rb', line 8

def initialize(tags: [])
  @tags = tags
end

Instance Attribute Details

#tagsObject

Returns the value of attribute tags.



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

def tags
  @tags
end

Class Method Details

.from_hash(h) ⇒ Object



22
23
24
25
26
27
# File 'lib/sarif/property_bag.rb', line 22

def self.from_hash(h)
  return nil if h.nil?
  new(
    tags: h["tags"] || []
  )
end

Instance Method Details

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



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

def ==(other)
  return false unless other.is_a?(PropertyBag)
  @tags == other.tags
end

#hashObject



36
37
38
# File 'lib/sarif/property_bag.rb', line 36

def hash
  [@tags].hash
end

#to_hObject



12
13
14
15
16
# File 'lib/sarif/property_bag.rb', line 12

def to_h
  h = {}
  h["tags"] = @tags if @tags&.any?
  h
end

#to_json(pretty: false) ⇒ Object



18
19
20
# File 'lib/sarif/property_bag.rb', line 18

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