#!/bin/sh

Details() {
   cat <<EOF
This was presented on 'Scam School'.  Watch the video at
http://revision3.com/scamschool/mindcontrolscam/ to see the guy
deliver it.  Heres an overview:

=== Scam ===
Read the following poem:

The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.

Now, think of a playing card ... Any card.

> 10 of Clubs

Really? Had you seen this before ? I can't believe this.

=== Answer ===
Hearts: Reverend
Clubs: Coach
Spades: Professor
Diamonds: Doctor

1-5 Singleton
6-10: Doubleday
11-13: Tripplet

1 : Alfred
2 : Byron
3 : Charles
4 : David
5 : Edgar

EOF
}

Usage() {
   cat <<EOF
${0##*/} card
  give the name of the expert for the given card for the scam at
  http://revision3.com/scamschool/mindcontrolscam/

  Example:
  ${0##*/} 9H
    show name and link for "9 of Hearts"
  ${0##*/} details
    show details on the scam

EOF
}
error() { echo "$@" 1>&2; }
fail() { [ $# -eq 0 ] || error "$@"; exit 1; }

[ $# -ne 1 ] && { Usage 1>&2; exit 1; }
[ "$1" = "-h" -o "$1" = "--help" ] && { Usage; exit 0; }

[ "${1}" = "--details" -o "${1}" = "-d" -o "${1}" = "details" ] &&
   { Details; exit 0; }
card=${1}
card=$(echo "${card}" | tr '[a-z]' '[A-Z]')

num=${card%?}
suit=${card#?}

[ "${num}${suit}" = "${card}" ] || fail "bad card ${card}"

case "${num}" in
   A|6|J) fname="Alfred"  ;;
   2|7|Q) fname="Byron"   ;;
   3|8|K) fname="Charles" ;;
   4|9)   fname="David"   ;;
   5|10)  fname="Edgar"   ;;
esac

case "${num}" in
   A|2|3|4|5)  lname="Singleton";;
   6|7|8|9|10) lname="Doubleday";;
   J|Q|K)      lname="Tripplet";;
esac

case "${suit}" in
  Hearts|H)   title="Reverend";;
  Clubs|C)    title="Coach";;
  Spades|S)   title="Professor";;
  Diamonds|D) title="Doctor";;
esac

echo "${title} ${fname} ${lname}"
echo "http://www.youtube.com/results?search_query=${title}+${fname}+${lname}"
