<commit_before>class LocalTransactionLocationIdentifier
  def self.find_slug(areas, content_item, tier_override = nil)
    new(areas, content_item, tier_override).find_slug
  end

  attr_reader :areas, :content_item, :tier_override

  def initialize(areas, content_item, tier_override = nil)
    @areas = areas
    @content_item = content_item
    @tier_override = tier_override
  end

  def find_slug
    matching_authority_by_tier_slug
  end

private

  def matching_authority_by_tier_slug
    matching_authority_by_tier.try(:[], "codes").try(:[], "govuk_slug")
  end

  def matching_authority_by_tier
    return nil unless service_providing_tiers

    service_providing_tiers.each do |tier|
      areas.each do |area|
        return area if tier == identify_tier(area["type"])
      end
    end
    nil
  end

  def authority_types
    %w(DIS LBO UTA CTY LGD MTD COI)
  end

  def identify_tier(type)
    case type
    when 'DIS' then 'district'
    when 'CTY' then 'county'
    when 'LBO', 'MTD', 'UTA', 'COI' then 'unitary'
    end
  end

  def service_providing_tiers
    return unless content_item

    content_item["details"].try(:[], "service_tiers")
  end
end<commit_msg>Add LGD to the area types that we support<commit_after>class LocalTransactionLocationIdentifier
  def self.find_slug(areas, content_item, tier_override = nil)
    new(areas, content_item, tier_override).find_slug
  end

  attr_reader :areas, :content_item, :tier_override

  def initialize(areas, content_item, tier_override = nil)
    @areas = areas
    @content_item = content_item
    @tier_override = tier_override
  end

  def find_slug
    matching_authority_by_tier_slug
  end

private

  def matching_authority_by_tier_slug
    matching_authority_by_tier.try(:[], "codes").try(:[], "govuk_slug")
  end

  def matching_authority_by_tier
    return nil unless service_providing_tiers

    service_providing_tiers.each do |tier|
      areas.each do |area|
        return area if tier == identify_tier(area["type"])
      end
    end
    nil
  end

  def authority_types
    %w(DIS LBO UTA CTY LGD MTD COI)
  end

  def identify_tier(type)
    case type
    when 'DIS' then 'district'
    when 'CTY' then 'county'
    when 'LBO', 'LGD', 'MTD', 'UTA', 'COI' then 'unitary'
    end
  end

  def service_providing_tiers
    return unless content_item

    content_item["details"].try(:[], "service_tiers")
  end
end
{'fraction_non_alphanumeric': 0.08552357113057989, 'fraction_numerical': 0.0, 'mean_word_length': 3.739130434782609, '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': '5097903', 'n_tokens_mistral': 842, 'n_tokens_neox': 821, 'n_words': 206}