<commit_before>require "gds_api/fact_cave"

class GovspeakPresenter
  EMBEDDED_FACT_REGEXP = /\[fact\:([a-z0-9-]+)\]/i # e.g. [fact:vat-rates]

  def initialize(markup)
    @markup = markup
  end

  def html
    markdown_with_facts = interpolate_fact_values(@markup)
    Govspeak::Document.new(markdown_with_facts).to_html.html_safe
  end

  private

  def interpolate_fact_values(string)
    return string if !string.match(EMBEDDED_FACT_REGEXP)

    string.gsub(EMBEDDED_FACT_REGEXP) do |match|
      if fact = $fact_cave.fact($1)
        fact.details.value
      else
        ''
      end
    end
  end
end
<commit_msg>Use `unless` instead of if negate<commit_after>require "gds_api/fact_cave"

class GovspeakPresenter
  EMBEDDED_FACT_REGEXP = /\[fact\:([a-z0-9-]+)\]/i # e.g. [fact:vat-rates]

  def initialize(markup)
    @markup = markup
  end

  def html
    markdown_with_facts = interpolate_fact_values(@markup)
    Govspeak::Document.new(markdown_with_facts).to_html.html_safe
  end

  private

  def interpolate_fact_values(string)
    return string unless string.match(EMBEDDED_FACT_REGEXP)

    string.gsub(EMBEDDED_FACT_REGEXP) do |match|
      if fact = $fact_cave.fact($1)
        fact.details.value
      else
        ''
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.10513833992094862, 'fraction_numerical': 0.0047430830039525695, 'mean_word_length': 3.306122448979592, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7642054', 'n_tokens_mistral': 509, 'n_tokens_neox': 485, 'n_words': 81}