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