From 6fdeffebf1093664bb769acccb9c6a356b825cf0 Mon Sep 17 00:00:00 2001 From: Emi Matchu Date: Sat, 31 Aug 2024 13:37:12 -0700 Subject: [PATCH] Simplify PetType.random_basic_per_species I'm mostly just going around looking for `special_color`, a concept I think the app doesn't use anymore, and removing it where I see it! --- app/models/pet_type.rb | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/app/models/pet_type.rb b/app/models/pet_type.rb index b34d2910..31602ad8 100644 --- a/app/models/pet_type.rb +++ b/app/models/pet_type.rb @@ -11,23 +11,18 @@ class PetType < ApplicationRecord BasicHashes = YAML::load_file(Rails.root.join('config', 'basic_type_hashes.yml')) + scope :basic, -> { joins(:color).merge(Color.basic) } scope :matching_name, ->(color_name, species_name) { color = Color.find_by_name!(color_name) species = Species.find_by_name!(species_name) where(color_id: color.id, species_id: species.id) } - def self.special_color_or_basic(special_color) - color_ids = special_color ? [special_color.id] : Color.basic.select([:id]).map(&:id) - where(color_id: color_ids) - end - def self.random_basic_per_species(species_ids) random_pet_types = [] - # TODO: omg so lame :P - standards = special_color_or_basic(nil).group_by(&:species_id) + basics_by_species_id = basic.group_by(&:species_id) species_ids.each do |species_id| - pet_types = standards[species_id] + pet_types = basics_by_species_id[species_id] random_pet_types << pet_types[rand(pet_types.size)] if pet_types end random_pet_types