Class: Sarif::MultiformatMessageString

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

Overview

A message string or message format string rendered in multiple formats.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text:, markdown: nil, properties: nil) ⇒ MultiformatMessageString

Returns a new instance of MultiformatMessageString.



8
9
10
11
12
# File 'lib/sarif/multiformat_message_string.rb', line 8

def initialize(text:, markdown: nil, properties: nil)
  @text = text
  @markdown = markdown
  @properties = properties
end

Instance Attribute Details

#markdownObject

Returns the value of attribute markdown.



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

def markdown
  @markdown
end

#propertiesObject

Returns the value of attribute properties.



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

def properties
  @properties
end

#textObject

Returns the value of attribute text.



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

def text
  @text
end

Class Method Details

.from_hash(h) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/sarif/multiformat_message_string.rb', line 26

def self.from_hash(h)
  return nil if h.nil?
  new(
    text: h["text"],
    markdown: h["markdown"],
    properties: h["properties"]
  )
end

Instance Method Details

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



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

def ==(other)
  return false unless other.is_a?(MultiformatMessageString)
  @text == other.text && @markdown == other.markdown && @properties == other.properties
end

#hashObject



42
43
44
# File 'lib/sarif/multiformat_message_string.rb', line 42

def hash
  [@text, @markdown, @properties].hash
end

#to_hObject



14
15
16
17
18
19
20
# File 'lib/sarif/multiformat_message_string.rb', line 14

def to_h
  h = {}
  h["text"] = @text
  h["markdown"] = @markdown unless @markdown.nil?
  h["properties"] = @properties unless @properties.nil?
  h
end

#to_json(pretty: false) ⇒ Object



22
23
24
# File 'lib/sarif/multiformat_message_string.rb', line 22

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