<commit_before>class Organization < ActiveRecord::Base
  has_many :admins
  has_many :printers
  has_many :toners

  validates :name, uniqueness: {}

  attr_accessor :_printer_model_ids, :_toner_models

  def to_s
    self.name + " (" + self.description + ")"
  end

  def short_description
    "#{self.name} - #{self.description[0..70]}"
  end

  def printer_model_ids
    @_printer_model_ids ||= self.printers.map(&:printer_model_id).uniq
  end

  def toner_models
    @_toner_models ||= TonerModel.includes(:printer_models).where('printer_models_toner_models.printer_model_id': printer_model_ids)
  end

  # toners (in tutte organizations) for my printers
  def available_toners
    Toner.where(toner_model: toner_models.map(&:id)).where(gift: true)
  end

  def admins_string
    self.admins.map {|admin| admin.to_s}.join(', ')
  end

  def interested?(toner)
    @printer_model_ids ||= self.printers.map(&:printer_model_id)
    (toner.toner_model.printer_model_ids.to_a & @printer_model_ids).size > 0 
  end<commit_msg>refactor printer_models and toner for organization<commit_after>class Organization < ActiveRecord::Base
  has_many :admins
  has_many :printers
  has_many :toners

  validates :name, uniqueness: {}

  # cache
  attr_accessor :_printer_model_ids, 
                :_usable_toner_models

  def to_s
    self.name + " (" + self.description + ")"
  end

  def short_description
    "#{self.name} - #{self.description[0..70]}"
  end

  def admins_string
    self.admins.map {|admin| admin.to_s}.join(', ')
  end

  def printer_model_ids
    @_printer_model_ids ||= self.printers.select(:printer_model_id).map(&:printer_model_id).uniq
  end

  def usable_toner_models
    @_usable_toner_models ||= TonerModel.includes(:printer_models).where('printer_models_toner_models.printer_model_id': printer_model_ids)
  end

  # toners (in tutte organizations) for my printers
  def available_toners
    Toner.where(toner_model: usable_toner_models.map(&:id)).where(gift: true)
  end

  def interested_in?(toner)
    usable_toner_models.map(&:id).include?(toner.toner_model_id)
  end
{'fraction_non_alphanumeric': 0.1128646580583453, 'fraction_numerical': 0.003347680535628886, 'mean_word_length': 4.433766233766233, 'pattern_counts': {'":': 0, '<': 5, '<?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': '3712683', 'n_tokens_mistral': 785, 'n_tokens_neox': 748, 'n_words': 127}