Class: Sarif::PropertyBag
- Inherits:
-
Object
- Object
- Sarif::PropertyBag
- Defined in:
- lib/sarif/property_bag.rb
Overview
Key/value pairs that provide additional information about the object.
Instance Attribute Summary collapse
-
#tags ⇒ Object
Returns the value of attribute tags.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(tags: []) ⇒ PropertyBag
constructor
A new instance of PropertyBag.
- #to_h ⇒ Object
- #to_json(pretty: false) ⇒ Object
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 = end |
Instance Attribute Details
#tags ⇒ Object
Returns the value of attribute tags.
6 7 8 |
# File 'lib/sarif/property_bag.rb', line 6 def @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. end |
#hash ⇒ Object
36 37 38 |
# File 'lib/sarif/property_bag.rb', line 36 def hash [@tags].hash end |
#to_h ⇒ Object
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 |