Class: DataChecks::Notifiers::EmailDefaultFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/data_checks/notifiers/email_default_formatter.rb

Instance Method Summary collapse

Constructor Details

#initialize(check_result) ⇒ EmailDefaultFormatter

Returns a new instance of EmailDefaultFormatter.



6
7
8
9
# File 'lib/data_checks/notifiers/email_default_formatter.rb', line 6

def initialize(check_result)
  @check_run = check_result.check.check_run
  @check_result = check_result
end

Instance Method Details

#bodyObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/data_checks/notifiers/email_default_formatter.rb', line 15

def body
  error = @check_run.error_message
  count = @check_result.count
  entries = @check_result.entries&.map { |entry| format_entry(entry) }

  if error
    "<p>#{error}</p>"
  else
    body = "<p>Checker found #{count} element(s).</p>"
    if entries
      if count > 10
        body += "<p>Showing 10 of #{count} entries</p>"
      end

      body += format("<ul>%s</ul>", entries.map { |entry| "<li>#{entry}</li>" }.join)
    end
    body
  end
end

#subjectObject



11
12
13
# File 'lib/data_checks/notifiers/email_default_formatter.rb', line 11

def subject
  "Check #{@check_run.status.titleize}: #{@check_run.name}"
end