Class: Sheetah::Messaging::Message

Inherits:
Object
  • Object
show all
Includes:
Validations
Defined in:
lib/sheetah/messaging/message.rb

Direct Known Subclasses

MessageVariant

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Validations

included, #validate

Constructor Details

#initialize(code:, code_data: nil, scope: SCOPES::SHEET, scope_data: nil, severity: SEVERITIES::WARN) ⇒ Message

Returns a new instance of Message.



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/sheetah/messaging/message.rb', line 11

def initialize(
  code:,
  code_data: nil,
  scope: SCOPES::SHEET,
  scope_data: nil,
  severity: SEVERITIES::WARN
)
  @code        = code
  @code_data   = code_data
  @scope       = scope
  @scope_data  = scope_data
  @severity    = severity
end

Instance Attribute Details

#codeObject

Returns the value of attribute code.



25
26
27
# File 'lib/sheetah/messaging/message.rb', line 25

def code
  @code
end

#code_dataObject

Returns the value of attribute code_data.



25
26
27
# File 'lib/sheetah/messaging/message.rb', line 25

def code_data
  @code_data
end

#scopeObject

Returns the value of attribute scope.



25
26
27
# File 'lib/sheetah/messaging/message.rb', line 25

def scope
  @scope
end

#scope_dataObject

Returns the value of attribute scope_data.



25
26
27
# File 'lib/sheetah/messaging/message.rb', line 25

def scope_data
  @scope_data
end

#severityObject

Returns the value of attribute severity.



25
26
27
# File 'lib/sheetah/messaging/message.rb', line 25

def severity
  @severity
end

Instance Method Details

#==(other) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/sheetah/messaging/message.rb', line 33

def ==(other)
  other.is_a?(self.class) &&
    code       == other.code &&
    code_data  == other.code_data &&
    scope      == other.scope &&
    scope_data == other.scope_data &&
    severity   == other.severity
end

#to_hObject



48
49
50
51
52
53
54
55
56
# File 'lib/sheetah/messaging/message.rb', line 48

def to_h
  {
    code: code,
    code_data: code_data,
    scope: scope,
    scope_data: scope_data,
    severity: severity,
  }
end

#to_sObject



42
43
44
45
46
# File 'lib/sheetah/messaging/message.rb', line 42

def to_s
  parts = [scoping_to_s, "#{severity}: #{code}", code_data]
  parts.compact!
  parts.join(" ")
end