Class: Newshound::Warnings::Base

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

Overview

Base class for warning source adapters Each adapter is responsible for:

  1. Fetching recent warnings from its specific data source

  2. Formatting warning data for reports and banners

Subclasses must implement:

  • #recent(time_range:, limit:) - Returns a collection of warning records

  • #format_for_report(warning, number) - Formats a single warning for Slack/report display

  • #format_for_banner(warning) - Formats a single warning for banner UI

Instance Method Summary collapse

Instance Method Details

#format_for_banner(warning) ⇒ Hash

Formats a warning for banner UI display

Parameters:

  • warning (Object)

    Warning record from the data source

Returns:

  • (Hash)

    Hash with keys: :id, :title, :message, :location, :time

Raises:

  • (NotImplementedError)


37
38
39
# File 'lib/newshound/warnings/base.rb', line 37

def format_for_banner(warning)
  raise NotImplementedError, "#{self.class} must implement #format_for_banner"
end

#format_for_report(warning, number) ⇒ String

Formats a warning for report/Slack display

Parameters:

  • warning (Object)

    Warning record from the data source

  • number (Integer)

    Position number in the list

Returns:

  • (String)

    Formatted markdown text for display

Raises:

  • (NotImplementedError)


29
30
31
# File 'lib/newshound/warnings/base.rb', line 29

def format_for_report(warning, number)
  raise NotImplementedError, "#{self.class} must implement #format_for_report"
end

#recent(time_range:, limit:) ⇒ Array

Fetches recent warnings from the data source

Parameters:

  • time_range (ActiveSupport::Duration)

    Time duration to look back (e.g., 24.hours)

  • limit (Integer)

    Maximum number of warnings to return

Returns:

  • (Array)

    Collection of warning records

Raises:

  • (NotImplementedError)


20
21
22
# File 'lib/newshound/warnings/base.rb', line 20

def recent(time_range:, limit:)
  raise NotImplementedError, "#{self.class} must implement #recent"
end