class ManualSectionIndexableFormatter
  def initialize(section, manual)
    @section = section
    @manual = manual
  end

  def type
    "manual_section"
  end

  def id
    link
  end

  def indexable_attributes
    {
      title: "#{manual.title}: #{section.title}",
      description: section.summary,
      link: link,
      indexable_content: section.body,
      organisations: [manual.organisation_slug],
      manual: manual.slug,
    }
  end

private
  attr_reader :section, :manual

  def extra_attributes
    {}
  end

  def link
    with_leading_slash(section.slug)
  end

  def with_leading_slash(slug)
    slug.start_with?("/") ? slug : "/#{slug}"
  end
end

require "formatters/abstract_indexable_formatter"

class ManualSectionIndexableFormatter < AbstractIndexableFormatter
  def initialize(section, manual)
    @entity = section
    @manual = manual
  end

  def type
    "manual_section"
  end

private
  attr_reader :manual

  def extra_attributes
    {
      manual: manual.slug,
    }
  end

  def title
    "#{manual.title}: #{entity.title}"
  end

  def description
    entity.summary
  end

  def link
    with_leading_slash(entity.slug)
  end

  def indexable_content
    entity.body
  end

  def last_update
    nil
  end

  def organisation_slugs
    [manual.organisation_slug]
  end
end

Refactor ManualSectionIndexableFormatter to use abstract class
Refactor ManualSectionIndexableFormatter to use abstract class

This avoids duplication of with_leading_slash, and makes this formatter more
consistent with the others.

The main change here is to override private methods from the superclass
instead of defining the attributes entirely in indexable_attributes. This
makes it clearer that the only attribute unique to this formatter is the
manual.
