<commit_before>module MappingsHelper

  ##
  # Twitter bootstrap-flavour tabs.
  # Produce a <ul class="nav nav-tabs">
  # with list items with links in them.
  # e.g.
  #
  #   +bootstrap_flavour_tabs(
  #      {
  #        'Edit'    => edit_path,
  #        'History' => history_path
  #      }, active: 'Edit'
  #    )
  def bootstrap_flavour_tabs(titles_to_links, options)
    content_tag :ul, class: 'nav nav-tabs' do
      titles_to_links.inject('') do |result, title_link|
        title, href       = title_link[0], title_link[1]
        active            = options[:active] == title
        html_opts         = {}
        html_opts[:class] = 'active' if active

        result << content_tag(:li, html_opts) do
          link_to(title, active ? '#' : href)
        end
      end.html_safe
    end
  end

  ##
  # Tabs for mapping editing
  def mapping_edit_tabs(options = {})
    if @mapping.versions.any?
      content_tag :div, class: 'add-bottom-margin' do
        bootstrap_flavour_tabs(
          {
            'Edit'    => edit_site_mapping_path(@mapping.site, @mapping),
            'History' => site_mapping_versions_path(@mapping.site, @mapping)
          },
          options)
      end
    end
  end

  ##
  # Return a FormBuilder-compatible list of mapping types
  # e.g. [['Redirect', 'redirect'], ['Archive', 'archive']]
  def options_for_supported_types
    Mapping::SUPPORTED_TYPES.map do |type|
      ["#{type.titleize}", type]
    end
  end

  OTHER_OPERATIONS = { 'tag' => 'tag' }
  def http_status_name(http_status)
    if http_status == '301'
      'Redirect'
    elsif http_status == '410'
      'Archive'
    end
  end

  ##
  # Convert 'redirect'/'archive'/'tag' into 'Redirect'/'Archive'/'Tag' to use in title and heading
  # for edit_multiple
  def operation_name(operation)
    (operation.titleize if Mapping::SUPPORTED_TYPES.include?(operation)) || OTHER_OPERATIONS[operation].titleize
  end

  def friendly_hit_count(hit_count)
    hit_count ? number_with_delimiter(hit_count) : '0'
  end

  def friendly_hit_percentage(hit_percentage)
    case
      when hit_percentage.zero?  then ''
      when hit_percentage < 0.01 then '< 0.01%'
      when hit_percentage < 10.0 then hit_percentage.round(2).to_s + '%'
      else hit_percentage.round(1).to_s + '%'
    end
  end

  def show_preview_links?
    @site.default_host.aka_host &&
      @site.default_host.aka_host.redirected_by_gds? &&<commit_msg>Simplify operation_name mappings helper method<commit_after>module MappingsHelper

  ##
  # Twitter bootstrap-flavour tabs.
  # Produce a <ul class="nav nav-tabs">
  # with list items with links in them.
  # e.g.
  #
  #   +bootstrap_flavour_tabs(
  #      {
  #        'Edit'    => edit_path,
  #        'History' => history_path
  #      }, active: 'Edit'
  #    )
  def bootstrap_flavour_tabs(titles_to_links, options)
    content_tag :ul, class: 'nav nav-tabs' do
      titles_to_links.inject('') do |result, title_link|
        title, href       = title_link[0], title_link[1]
        active            = options[:active] == title
        html_opts         = {}
        html_opts[:class] = 'active' if active

        result << content_tag(:li, html_opts) do
          link_to(title, active ? '#' : href)
        end
      end.html_safe
    end
  end

  ##
  # Tabs for mapping editing
  def mapping_edit_tabs(options = {})
    if @mapping.versions.any?
      content_tag :div, class: 'add-bottom-margin' do
        bootstrap_flavour_tabs(
          {
            'Edit'    => edit_site_mapping_path(@mapping.site, @mapping),
            'History' => site_mapping_versions_path(@mapping.site, @mapping)
          },
          options)
      end
    end
  end

  ##
  # Return a FormBuilder-compatible list of mapping types
  # e.g. [['Redirect', 'redirect'], ['Archive', 'archive']]
  def options_for_supported_types
    Mapping::SUPPORTED_TYPES.map do |type|
      ["#{type.titleize}", type]
    end
  end

  def http_status_name(http_status)
    if http_status == '301'
      'Redirect'
    elsif http_status == '410'
      'Archive'
    end
  end

  SUPPORTED_OPERATIONS = ['tag'] + Mapping::SUPPORTED_TYPES
  ##
  # Convert 'redirect'/'archive'/'tag' into 'Redirect'/'Archive'/'Tag'
  # to use in title and heading for edit_multiple
  def operation_name(operation)
    operation.titleize if SUPPORTED_OPERATIONS.include?(operation)
  end

  def friendly_hit_count(hit_count)
    hit_count ? number_with_delimiter(hit_count) : '0'
  end

  def friendly_hit_percentage(hit_percentage)
    case
      when hit_percentage.zero?  then ''
      when hit_percentage < 0.01 then '< 0.01%'
      when hit_percentage < 10.0 then hit_percentage.round(2).to_s + '%'
      else hit_percentage.round(1).to_s + '%'
    end
  end

  def show_preview_links?
    @site.default_host.aka_host &&
      @site.default_host.aka_host.redirected_by_gds? &&
{'fraction_non_alphanumeric': 0.11820233942130105, 'fraction_numerical': 0.008208495793145906, 'mean_word_length': 2.6980273141122915, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2621035', 'n_tokens_mistral': 1670, 'n_tokens_neox': 1609, 'n_words': 343}