(CNN) -- It was five days before Christmas, and luckily for Gem the puppy, the creature was stirring on the trash-sorting conveyor belt.
Workers at a trash- and recyclables-sorting facility in San Francisco found the poodle mix in a trash bag among other discarded material Friday evening -- just in time, because it was about to drop into a pile bound for a landfill, CNN affiliate KTVU reported.
The discovery likely saved the apricot pup's life.
"We could tell the puppy was still moving, and it was trying to crawl out of the bag itself," Gregory Foster, a material handler at the Recology facility, told KTVU. "Luckily we stopped the line in time before it actually fell off the belt into the pit."
The dog, believed to be a few months old, apparently was put in a bin of trash that Recology collected and drove to the facility. It was then put on the conveyor belt, where workers separate recyclables from landfill-bound trash, KTVU reported.
The animal control department named the puppy, noting it was a "precious little gem" among the trash, department Capt. Le-Ellis Brown told KGO.
The department said it is trying to determine who the puppy's owner was, how it was injured and how it got into the trash. Veterinarians will help the puppy heal before it is put up for adoption, KGO reported.