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 public_timestamp
    nil
  end

  def organisation_slugs
    [manual.organisation_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 manual_slug
    with_leading_slash(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 public_timestamp
    nil
  end

  def organisation_slugs
    [manual.organisation_slug]
  end
end

Prepend leading slash to a manual section's `manual` attribute
Prepend leading slash to a manual section's `manual` attribute

- For consistency with how the HMRC Manuals API deals with manual `id`s,
  `link`s and `manual` attributes in sections, don't strip leading
  slashes.
- This inconsistency was breaking search within a manual
  (https://trello.com/c/KAR7YtA7/119-searching-within-a-manual-uses-the-wrong-layout),
  so fix it!
