Class: ProblemCheck::Problem

Inherits:
Object
  • Object
show all
Defined in:
app/services/problem_check/problem.rb

Constant Summary collapse

PRIORITIES =
%w[low high].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, priority: "low", identifier: nil, target: nil, details: {}) ⇒ Problem

Returns a new instance of Problem.



8
9
10
11
12
13
14
# File 'app/services/problem_check/problem.rb', line 8

def initialize(message, priority: "low", identifier: nil, target: nil, details: {})
  @message = message
  @priority = PRIORITIES.include?(priority) ? priority : "low"
  @identifier = identifier
  @target = target
  @details = details
end

Instance Attribute Details

#detailsObject (readonly)

Returns the value of attribute details.



6
7
8
# File 'app/services/problem_check/problem.rb', line 6

def details
  @details
end

#identifierObject (readonly)

Returns the value of attribute identifier.



6
7
8
# File 'app/services/problem_check/problem.rb', line 6

def identifier
  @identifier
end

#messageObject (readonly)

Returns the value of attribute message.



6
7
8
# File 'app/services/problem_check/problem.rb', line 6

def message
  @message
end

#priorityObject (readonly)

Returns the value of attribute priority.



6
7
8
# File 'app/services/problem_check/problem.rb', line 6

def priority
  @priority
end

#targetObject (readonly)

Returns the value of attribute target.



6
7
8
# File 'app/services/problem_check/problem.rb', line 6

def target
  @target
end

Class Method Details

.from_h(h) ⇒ Object



25
26
27
28
29
30
31
# File 'app/services/problem_check/problem.rb', line 25

def self.from_h(h)
  h = h.with_indifferent_access

  return if h[:message].blank?

  new(h[:message], priority: h[:priority], identifier: h[:identifier])
end

Instance Method Details

#to_hObject Also known as: attributes



20
21
22
# File 'app/services/problem_check/problem.rb', line 20

def to_h
  { message: message, priority: priority, identifier: identifier }
end

#to_sObject



16
17
18
# File 'app/services/problem_check/problem.rb', line 16

def to_s
  @message
end