#!/bin/bash
sink=$(pacmd list-sinks | grep '* index:')
if [[ "${sink:11:11}" -eq "1" ]]
then
echo 'usb'
else
echo 'mic'
fi
This is making a lot of assumptions, as you did not explain much about the ruby script you pasted and what the actual objective is.
This bash script does a grep on the output of the pulseaudo list of sinks, where the index is preceded with a *. then from this line, the 11th character is checked. If it is a 1 then echo out USB, otherwise MIC.
As said, this is presuming a lot and this style of programming can go hilariously wrong if there are other indexes in play, or you do want the name of the device...
I don't know i3bar or i3blocks, but it maybe that you need to set an interval in i3blocks or wrap the script in a while loop, because a script runs, outputs something and then exit's, so something should continuously trigger it. The way you do it is i3 specific, which I know nothing about. Based on the man pages, this is what I would try first
[pulse]
command=/usr/local/bin/check_pulse.sh
interval=15
http://manpages.ubuntu.com/manpages/bionic/man1/i3blocks.1.html