require_relative "../../lib/notification_file_lookup"

module NotificationHelper
  include ActionView::Helpers::TagHelper

  def banner_notification
    banner = NotificationFileLookup.instance.banner
    if banner
      content_tag(:section, "<div>#{banner[:file]}</div>", {:id => "banner-notification", :class => banner[:colour]}, false)
    else
      ''
    end
  end

  # This is only used to replace homepage campaigns for urgent matters.
  def campaign_replacement_notification
    campaign = NotificationFileLookup.instance.campaign
    if campaign
      content_tag(:section, "<div>#{campaign[:file]}</div>", {:id => "campaign-notification", :class => campaign[:colour]}, false)
    else
      ''
    end
  end
end

require_relative "../../lib/notification_file_lookup"

module NotificationHelper
  include ActionView::Helpers::TagHelper

  def banner_notification
    node_replacement_notification(NotificationFileLookup.instance.banner, "banner")
  end

  # Only used to replace homepage campaigns for urgent matters.
  def campaign_replacement_notification
    node_replacement_notification(NotificationFileLookup.instance.campaign, "campaign")
  end

  private

  def node_replacement_notification(node, type)
    if node
      content_tag(:section, "<div>#{node[:file]}</div>",
        {:id => "#{type}-notification", :class => node[:colour]}, false)
    else
      ''
    end
  end
end

Refactor duplicate method bodies into shared private method
Refactor duplicate method bodies into shared private method
