Class: Newshound::WarningReporter

Inherits:
Object
  • Object
show all
Defined in:
lib/newshound/warning_reporter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(warning_source: nil, configuration: nil, time_range: 24.hours) ⇒ WarningReporter

Returns a new instance of WarningReporter.



7
8
9
10
11
# File 'lib/newshound/warning_reporter.rb', line 7

def initialize(warning_source: nil, configuration: nil, time_range: 24.hours)
  @configuration = configuration || Newshound.configuration
  @warning_source = resolve_warning_source(warning_source)
  @time_range = time_range
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



5
6
7
# File 'lib/newshound/warning_reporter.rb', line 5

def configuration
  @configuration
end

#time_rangeObject (readonly)

Returns the value of attribute time_range.



5
6
7
# File 'lib/newshound/warning_reporter.rb', line 5

def time_range
  @time_range
end

#warning_sourceObject (readonly)

Returns the value of attribute warning_source.



5
6
7
# File 'lib/newshound/warning_reporter.rb', line 5

def warning_source
  @warning_source
end

Instance Method Details

Returns data formatted for the banner UI



30
31
32
33
34
35
36
# File 'lib/newshound/warning_reporter.rb', line 30

def banner_data
  return {warnings: []} unless warning_source

  {
    warnings: recent_warnings.map { |warning| warning_source.format_for_banner(warning) }
  }
end

#generate_reportObject Also known as: report



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/newshound/warning_reporter.rb', line 13

def generate_report
  return no_warnings_block if recent_warnings.empty?

  [
    {
      type: "section",
      text: {
        type: "mrkdwn",
        text: "*⚠️ Recent Warnings (Last 24 Hours)*"
      }
    },
    *format_warnings
  ]
end