From fdf1f318676dedfda1ac941f0df217bfc105c870 Mon Sep 17 00:00:00 2001 From: Emi Matchu Date: Fri, 13 Sep 2024 18:59:17 -0700 Subject: [PATCH] Add `pets:find` task to look up pets of a given color/species --- lib/tasks/pets.rake | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/tasks/pets.rake b/lib/tasks/pets.rake index 9abec64b..03ab4319 100644 --- a/lib/tasks/pets.rake +++ b/lib/tasks/pets.rake @@ -3,4 +3,20 @@ namespace :pets do task :load, [:name] => [:environment] do |task, args| pp Pet.fetch_viewer_data(args[:name]) end + + desc "Find pets that were, last we saw, of the given color and species" + task :find, [:color_name, :species_name] => [:environment] do |task, args| + begin + pt = PetType.matching_name(args.color_name, args.species_name).first! + rescue ActiveRecord::RecordNotFound + abort "Could not find pet type for " + + "#{args.color_name} #{args.species_name}" + end + + limit = ENV.fetch("LIMIT", 10) + + pt.pets.limit(limit).order(id: :desc).pluck(:name).each do |pet_name| + puts "- #{pet_name} (https://www.neopets.com/petlookup.phtml?pet=#{pet_name})" + end + end end