Class: Sheetah::Messaging::Message

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

Overview

TODO: list all possible message code in a systematic way, so that i18n do not miss any by mistake.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code:, code_data: nil, scope: nil, scope_data: nil, severity: nil) ⇒ Message

Returns a new instance of Message.



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/sheetah/messaging.rb', line 20

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

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



34
35
36
# File 'lib/sheetah/messaging.rb', line 34

def code
  @code
end

#code_dataObject (readonly)

Returns the value of attribute code_data.



34
35
36
# File 'lib/sheetah/messaging.rb', line 34

def code_data
  @code_data
end

#scopeObject (readonly)

Returns the value of attribute scope.



34
35
36
# File 'lib/sheetah/messaging.rb', line 34

def scope
  @scope
end

#scope_dataObject (readonly)

Returns the value of attribute scope_data.



34
35
36
# File 'lib/sheetah/messaging.rb', line 34

def scope_data
  @scope_data
end

#severityObject (readonly)

Returns the value of attribute severity.



34
35
36
# File 'lib/sheetah/messaging.rb', line 34

def severity
  @severity
end

Instance Method Details

#==(other) ⇒ Object



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

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_sObject



51
52
53
54
55
# File 'lib/sheetah/messaging.rb', line 51

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