<commit_before>class Organisation
  cattr_writer :organisations

  attr_reader :id, :name, :abbreviation

  def initialize(attrs)
    @id = attrs[:id]
    @name = attrs[:name]
    @abbreviation = attrs[:abbreviation]
  end

  def name_with_abbreviation
    if abbreviation.present? && abbreviation != name
      # Use square brackets around the abbreviation
      # as Chosen doesn't like matching with
      # parentheses at the start of a word
      "#{name} [#{abbreviation}]"
    else
      name
    end
  end

  def self.all
    @@organisations ||= self.load_organisations
  end

  def self.find(id)
    all.find { |organisation| organisation.id == id }
  end

  private
  def self.load_organisations
    (need_api.organisations || []).map {|attrs|
      self.new(attrs.symbolize_keys)
    }
  end

  def self.need_api
    ContentPlanner.needs_api
  end
end
<commit_msg>Reject excempt orgs and pull the parent orgs to the top<commit_after>class Organisation
  cattr_writer :organisations

  attr_reader :id, :name, :abbreviation, :parent_ids, :govuk_status

  def initialize(attrs)
    @id = attrs[:id]
    @name = attrs[:name]
    @abbreviation = attrs[:abbreviation]
    @parent_ids = attrs[:parent_ids]
    @govuk_status = attrs[:govuk_status]
  end

  def exempt?
    @govuk_status == "exempt"
  end

  def name_with_abbreviation
    if abbreviation.present? && abbreviation != name
      # Use square brackets around the abbreviation
      # as Chosen doesn't like matching with
      # parentheses at the start of a word
      "#{name} [#{abbreviation}]"
    else
      name
    end
  end

  def self.all
    @@organisations ||= self.load_organisations
  end

  def self.find(id)
    all.find { |organisation| organisation.id == id }
  end

  private
  def self.load_organisations
    (need_api.organisations || []).map {|attrs|
      self.new(attrs.symbolize_keys)
    }.reject { |org| org.exempt? }.sort { |a,b| a.parent_ids.count <=> b.parent_ids.count }
  end

  def self.need_api
    ContentPlanner.needs_api
  end
end

{'fraction_non_alphanumeric': 0.10122850122850123, 'fraction_numerical': 0.0, 'mean_word_length': 3.129817444219067, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '2196865', 'n_tokens_mistral': 727, 'n_tokens_neox': 670, 'n_words': 174}