require 'singleton'

class NickNames
  include Singleton

  def self.[](first_name)
    instance.equivalencies_for(first_name)
  end

  def equivalencies_for(first_name)
    first_name = first_name.dup.downcase

    (
      [first_name] \
        | long_for(first_name) \
        | short_for(first_name) \
        | (short_for(long_for(first_name).first) || [])
    ).sort
  end

  class <<self
    def method_missing(name, *args)
      NickNames.instance.__send__(name, args[0])
    end
  end

  def short_for(long_name)
    @long_to_short[long_name] || []
  end
  alias_method :nick_names_for, :short_for

  def long_for(short_name)
    @short_to_long[short_name] || []
  end

  def initialize
    equivalencies = [
      %w[abbie                abigail             ],
      %w[abby                 abigail             ],
      %w[abe                  abraham             ],
      %w[abe                  abram               ],
      %w[ada                  adaline             ],
      %w[addy                 adaline             ],
      %w[aggy                 agatha              ],
      %w[aggy                 agnes               ],
      %w[aggy                 augusta             ],
      %w[aggy                 augustina           ],
      %w[al                   alan                ],
      %w[al                   albert              ],
      %w[al                   aldo                ],
      %w[al                   alexander           ],
      %w[al                   alfonse             ],
      %w[al                   alfred              ],
      %w[al                   allan               ],
      %w[al                   allen               ],
      %w[al                   alonzo              ],
      %w[alex                 alexander           ],
      %w[alex                 alexandra           ],
      %w[allie                alice               ],
      %w[allie                alicia              ],
      %w[allie                almena              ],
      %w[andy                 anderson            ],
      %w[andy                 andrew              ],
      %w[ann                  antoinette          ],
      %w[ann                  antonia             ],
      %w[ann                  rosaenn             ],
      %w[ann                  rosaenna            ],
      %w[ann                  roxanne             ],
      %w[ann                  roxanna             ],
      %w[annie                ann                 ],
      %w[annie                anne                ],
      %w[ara                  arabella            ],
      %w[ara                  arabelle            ],
      %w[archie               archibald           ],
      %w[arly                 arlene              ],
      %w[art                  arthur              ],
      %w[babs                 barbara             ],
      %w[barbie               barbara             ],
      %w[barney               barnabas            ],
      %w[barney               bernard             ],
      %w[bart                 bartholomew         ],
      %w[bea                  beatrice            ],
      %w[becca                rebecca             ],
      %w[becky                rebecca             ],
      %w[bella                arabella            ],
      %w[bella                isabella            ],
      %w[bella                rosabella           ],
      %w[belle                arabella            ],
      %w[belle                belinda             ],
      %w[belle                isabel              ],
      %w[belle                isabelle            ],
      %w[belle                rosabel             ],
      %w[ben                  benedict            ],
      %w[ben                  benjamin            ],
      %w[benjy                benjamin            ],
      %w[bennie               benedict            ],
      %w[berny                bernard             ],
      %w[bert                 albert              ],
      %w[bert                 delbert             ],
      %w[bert                 elbert              ],
      %w[bert                 gilbert             ],
      %w[bert                 herbert             ],
      %w[bert                 hubert              ],
      %w[bert                 norbert             ],
      %w[bess                 elizabeth           ],
      %w[beth                 elizabeth           ],
      %w[betsy                elizabeth           ],
      %w[betty                elizabeth           ],
      %w[bill                 robert              ],
      %w[bill                 william             ],
      %w[billy                robert              ],
      %w[billy                william             ],
      %w[birdie               bertha              ],
      %w[birdie               roberta             ],
      %w[birtie               roberta             ],
      %w[bob                  robert              ],
      %w[bobbie               barbara             ],
      %w[bobbie               roberta             ],
      %w[bobby                robert              ],
      %w[brad                 bradford            ],
      %w[brody                broderick           ],
      %w[cal                  calvin              ],
      %w[cammie               camile              ],
      %w[carl                 charles             ],
      %w[carol                carolann            ],
      %w[carol                caroline            ],
      %w[cassie               caroline            ],
      %w[cassie               cassandra           ],
      %w[cassie               catherine           ],
      %w[cassie               cathleen            ],
      %w[cathy                catherine           ],
      %w[cathy                cathleen            ],
      %w[charlie              charles             ],
      %w[chet                 chester             ],
      %w[chris                christa             ],
      %w[chris                christian           ],
      %w[chris                christina           ],
      %w[chris                christine           ],
      %w[chris                christopher         ],
      %w[chris                kristen             ],
      %w[chris                kristin             ],
      %w[chris                kristy              ],
      %w[chuck                charles             ],
      %w[cindy                cinderlla           ],
      %w[cindy                cynthia             ],
      %w[clara                clarissa            ],
      %w[cliff                clifford            ],
      %w[cliff                clifton             ],
      %w[connie               constance           ],
      %w[crissy               chrintina           ],
      %w[crissy               chrintine           ],
      %w[curt                 curtis              ],
      %w[cy                   cyrus               ],
      %w[dan                  daniel              ],
      %w[danny                daniel              ],
      %w[dave                 david               ],
      %w[davey                david               ],
      %w[deb                  deborah             ],
      %w[deb                  debra               ],
      %w[debbie               deborah             ],
      %w[debbie               debra               ],
      %w[dee                  delores             ],
      %w[del                  delbert             ],
      %w[della                delores             ],
      %w[dennie               dennis              ],
      %w[dennis               dennison            ],
      %w[denny                dennis              ],
      %w[dick                 richard             ],
      %w[dolly                dorothy             ],
      %w[dom                  domenic             ],
      %w[dom                  dominico            ],
      %w[don                  donald              ],
      %w[don                  donato              ],
      %w[donnie               donald              ],
      %w[donny                donald              ],
      %w[dora                 dorothy             ],
      %w[dora                 eldora              ],
      %w[dora                 isadora             ],
      %w[dot                  dorothy             ],
      %w[dottie               dorothy             ],
      %w[dotty                dorothy             ],
      %w[drew                 andrew              ],
      %w[ed                   edgar               ],
      %w[ed                   edmond              ],
      %w[ed                   edmund              ],
      %w[ed                   eduardo             ],
      %w[ed                   edward              ],
      %w[ed                   edwin               ],
      %w[eddie                edgar               ],
      %w[eddie                edmond              ],
      %w[eddie                edmund              ],
      %w[eddie                eduardo             ],
      %w[eddie                edward              ],
      %w[eddie                edwin               ],
      %w[eddy                 edgar               ],
      %w[eddy                 edmond              ],
      %w[eddy                 edmund              ],
      %w[eddy                 eduardo             ],
      %w[eddy                 edward              ],
      %w[eddy                 edwin               ],
      %w[edie                 edith               ],
      %w[edie                 edyth               ],
      %w[edie                 edythe              ],
      %w[edye                 edyth               ],
      %w[edye                 edythe              ],
      %w[elaine               eleanor             ],
      %w[ella                 gabriella           ],
      %w[ellen                eleanor             ],
      %w[emily                amelia              ],
      %w[emily                emeline             ],
      %w[emma                 emeline             ],
      %w[emma                 emily               ],
      %w[eve                  genevieve           ],
      %w[fay                  faith               ],
      %w[flo                  florence            ],
      %w[flora                florence            ],
      %w[fran                 frances             ],
      %w[fran                 francine            ],
      %w[fran                 francis             ],
      %w[francie              frances             ],
      %w[francie              francine            ],
      %w[frank                francis             ],
      %w[frank                franklin            ],
      %w[frankie              francis             ],
      %w[frannie              frances             ],
      %w[frannie              francine            ],
      %w[franny               frances             ],
      %w[franny               francine            ],
      %w[fred                 alfred              ],
      %w[fred                 ferdinand           ],
      %w[fred                 frederick           ],
      %w[fred                 frieda              ],
      %w[fred                 winnifred           ],
      %w[freda                alfreda             ],
      %w[freda                fredericka          ],
      %w[freddie              ferdinand           ],
      %w[freddie              frederick           ],
      %w[freddie              frieda              ],
      %w[freddie              winnifred           ],
      %w[freddy               alfreda             ],
      %w[freddy               ferdinand           ],
      %w[freddy               frederick           ],
      %w[freddy               frieda              ],
      %w[freddy               winnifred           ],
      %w[gabby                gabriella           ],
      %w[gabby                gabrielle           ],
      %w[gabe                 gabriel             ],
      %w[gail                 abigail             ],
      %w[gene                 eugene              ],
      %w[geoff                geoffrey            ],
      %w[geoff                jeffrey             ],
      %w[george               georgine            ],
      %w[gerrie               geraldine           ],
      %w[gerry                gerald              ],
      %w[gerry                geraldine           ],
      %w[gertie               gertrude            ],
      %w[gil                  gilbert             ],
      %w[gina                 regina              ],
      %w[gretta               margaretta          ],
      %w[gus                  augustine           ],
      %w[gus                  augustus            ],
      %w[gwen                 gwendolyn           ],
      %w[hal                  harold              ],
      %w[hal                  henry               ],
      %w[hank                 henry               ],
      %w[hannah               johannah            ],
      %w[harry                harold              ],
      %w[harry                henry               ],
      %w[hattie               harriet             ],
      %w[henny                henrietta           ],
      %w[herb                 herbert             ],
      %w[hetty                hester              ],
      %w[hipsie               hipsbibah           ],
      %w[hugh                 hubert              ],
      %w[iggy                 ignatius            ],
      %w[issy                 isabel              ],
      %w[issy                 isabella            ],
      %w[issy                 isabelle            ],
      %w[issy                 isadora             ],
      %w[izzy                 isadore             ],
      %w[jake                 jacob               ],
      %w[jamie                benjamin            ],
      %w[jamie                james               ],
      %w[jan                  janet               ],
      %w[jay                  jacob               ],
      %w[jean                 genevieve           ],
      %w[jeb                  jebadiah            ],
      %w[jeff                 geoffrey            ],
      %w[jeff                 jefferson           ],
      %w[jeff                 jeffrey             ],
      %w[jennie               jennifer            ],
      %w[jenny                jennifer            ],
      %w[jenny                genevieve           ],
      %w[jerry                gerald              ],
      %w[jerry                geraldine           ],
      %w[jerry                jeremiah            ],
      %w[jessie               jessica             ],
      %w[jim                  james               ],
      %w[jimmie               james               ],
      %w[jimmy                james               ],
      %w[jo                   joan                ],
      %w[jo                   joann               ],
      %w[jo                   joanna              ],
      %w[jo                   joanne              ],
      %w[jo                   johanna             ],
      %w[jo                   johannah            ],
      %w[jo                   josophine           ],
      %w[jody                 joseph              ],
      %w[joe                  joseph              ],
      %w[joe                  joshua              ],
      %w[joey                 joseph              ],
      %w[joey                 josophine           ],
      %w[john                 johann              ],
      %w[john                 jonathan            ],
      %w[jon                  jonathan            ],
      %w[josey                josophine           ],
      %w[josh                 joshua              ],
      %w[joy                  joyce               ],
      %w[judy                 judith              ],
      %w[julie                julia               ],
      %w[kate                 katelin             ],
      %w[kate                 katelyn             ],
      %w[kate                 katherine           ],
      %w[kathy                katherine           ],
      %w[kathy                kathleen            ],
      %w[kathy                kathryn             ],
      %w[katy                 katherine           ],
      %w[katy                 kathleen            ],
      %w[kay                  katelin             ],
      %w[kay                  katelyn             ],
      %w[kay                  katherine           ],
      %w[kaye                 katelin             ],
      %w[kaye                 katelyn             ],
      %w[kaye                 katherine           ],
      %w[ken                  kenneth             ],
      %w[kenny                kenneth             ],
      %w[kim                  kimberley           ],
      %w[kim                  kimberly            ],
      %w[larry                laurence            ],
      %w[larry                lawrence            ],
      %w[lee                  elias               ],
      %w[lena                 aileen              ],
      %w[lena                 arlene              ],
      %w[lena                 cathleen            ],
      %w[lena                 darlene             ],
      %w[lena                 kathleen            ],
      %w[lena                 magdelina           ],
      %w[lenny                leonard             ],
      %w[leo                  leonard             ],
      %w[leon                 leonard             ],
      %w[leon                 napoleon            ],
      %w[les                  lester              ],
      %w[libby                elizabeth           ],
      %w[lilly                lillian             ],
      %w[linda                belinda             ],
      %w[linda                melinda             ],
      %w[lisa                 melissa             ],
      %w[liz                  elizabeth           ],
      %w[lizzie               elizabeth           ],
      %w[lois                 louise              ],
      %w[lorie                loretta             ],
      %w[lorie                lorraine            ],
      %w[lou                  louis               ],
      %w[lou                  louise              ],
      %w[lou                  lucinda             ],
      %w[lucy                 lucinda             ],
      %w[luke                 lucas               ],
      %w[luke                 lucias              ],
      %w[lynn                 caroline            ],
      %w[lynn                 carolyn             ],
      %w[maddy                madeline            ],
      %w[maddy                madelyn             ],
      %w[madge                magdelina           ],
      %w[madge                margaretta          ],
      %w[madie                madeline            ],
      %w[madie                madelyn             ],
      %w[maggie               madeline            ],
      %w[maggie               magdelina           ],
      %w[maggie               margaret            ],
      %w[maggy                margaret            ],
      %w[mandy                amanda              ],
      %w[marge                margaret            ],
      %w[marge                margaretta          ],
      %w[margie               margaret            ],
      %w[margie               marjorie            ],
      %w[margy                margaret            ],
      %w[margy                marjorie            ],
      %w[mark                 marcus              ],
      %w[marty                martin              ],
      %w[marv                 marvin              ],
      %w[matt                 mathew              ],
      %w[matt                 matthew             ],
      %w[maud                 madeline            ],
      %w[mel                  melinda             ],
      %w[mel                  melissa             ],
      %w[merv                 mervin              ],
      %w[mick                 michael             ],
      %w[mickey               michael             ],
      %w[mike                 michael             ],
      %w[mindy                melinda             ],
      %w[minnie               wilhelmina          ],
      %w[missy                melissa             ],
      %w[mitch                mitchell            ],
      %w[monty                lamont              ],
      %w[nat                  nathaniel           ],
      %w[nate                 nathan              ],
      %w[nate                 nathaniel           ],
      %w[nathan               jonathan            ],
      %w[neil                 cornelius           ],
      %w[newt                 newton              ],
      %w[nick                 nicholas            ],
      %w[nickie               nicholas            ],
      %w[nora                 eleanor             ],
      %w[nora                 lenora              ],
      %w[obie                 obediah             ],
      %w[ollie                oliver              ],
      %w[ozzy                 oswald              ],
      %w[pat                  patricia            ],
      %w[pat                  patrick             ],
      %w[patsy                patricia            ],
      %w[patty                patricia            ],
      %w[peggy                margaret            ],
      %w[penny                penelope            ],
      %w[pete                 peter               ],
      %w[phil                 philip              ],
      %w[phil                 phillip             ],
      %w[polly                paulina             ],
      %w[prissy               priscilla           ],
      %w[prudy                prudence            ],
      %w[randy                randolph            ],
      %w[ray                  raymond             ],
      %w[reba                 rebecca             ],
      %w[reggie               reginald            ],
      %w[rena                 irene               ],
      %w[rich                 aldrich             ],
      %w[rich                 richard             ],
      %w[richie               aldrich             ],
      %w[richie               richard             ],
      %w[rick                 derick              ],
      %w[rick                 ricardo             ],
      %w[rick                 richard             ],
      %w[ricky                broderick           ],
      %w[ricky                derick              ],
      %w[ricky                richard             ],
      %w[rob                  robert              ],
      %w[rob                  roberto             ],
      %w[robby                robert              ],
      %w[rod                  broderick           ],
      %w[ron                  aaron               ],
      %w[ron                  ronald              ],
      %w[ron                  veronica            ],
      %w[ronnie               aaron               ],
      %w[ronnie               ronald              ],
      %w[ronnie               veronica            ],
      %w[ronny                ronald              ],
      %w[ronny                veronica            ],
      %w[rose                 rosabel             ],
      %w[rose                 rosabella           ],
      %w[rose                 rosalyn             ],
      %w[rose                 roseann             ],
      %w[rose                 roseanna            ],
      %w[rose                 roxanna             ],
      %w[rose                 roxanne             ],
      %w[roz                  rosabel             ],
      %w[roz                  rosabella           ],
      %w[roz                  rosalyn             ],
      %w[rube                 reuben              ],
      %w[rudy                 rudolph             ],
      %w[russ                 russell             ],
      %w[rusty                russell             ],
      %w[sal                  solomon             ],
      %w[sam                  samuel              ],
      %w[sammy                samuel              ],
      %w[sandra               cassandra           ],
      %w[sandy                cassandra           ],
      %w[sandy                sandra              ],
      %w[scott                prescott            ],
      %w[scotty               prescott            ],
      %w[shelly               michelle            ],
      %w[shelly               rachel              ],
      %w[shelly               shelton             ],
      %w[sherry               shirley             ],
      %w[sly                  sylvester           ],
      %w[stella               estella             ],
      %w[steph                stephen             ],
      %w[steph                steven              ],
      %w[steve                stephen             ],
      %w[steve                steven              ],
      %w[sue                  susan               ],
      %w[sue                  susannah            ],
      %w[sully                sullivan            ],
      %w[susie                susan               ],
      %w[susie                susannah            ],
      %w[tabby                tabitha             ],
      %w[ted                  theodore            ],
      %w[teddy                theodore            ],
      %w[terry                terence             ],
      %w[tess                 teresa              ],
      %w[tess                 theresa             ],
      %w[tessa                teresa              ],
      %w[tessa                theresa             ],
      %w[tessie               teresa              ],
      %w[tessie               theresa             ],
      %w[thad                 thaddeus            ],
      %w[theo                 theodore            ],
      %w[thom                 thomas              ],
      %w[tilla                matilda             ],
      %w[tim                  timothy             ],
      %w[timmy                timothy             ],
      %w[tina                 augustina           ],
      %w[tina                 christina           ],
      %w[tina                 martina             ],
      %w[tish                 latisha             ],
      %w[tish                 tisha               ],
      %w[tisha                latisha             ],
      %w[toby                 tobias              ],
      %w[tom                  thom                ],
      %w[tom                  thomas              ],
      %w[tommy                thom                ],
      %w[tommy                thomas              ],
      %w[tony                 anthony             ],
      %w[tony                 shelton             ],
      %w[tori                 victoria            ],
      %w[torie                victoria            ],
      %w[torri                victoria            ],
      %w[torrie               victoria            ],
      %w[tory                 victoria            ],
      %w[trisha               patricia            ],
      %w[trixie               beatrice            ],
      %w[trudy                gertrude            ],
      %w[val                  valeri              ],
      %w[val                  valerie             ],
      %w[van                  sullivan            ],
      %w[vanna                vanessa             ],
      %w[vic                  victor              ],
      %w[vic                  vincent             ],
      %w[vic                  vincenzon           ],
      %w[vicki                victoria            ],
      %w[vickie               victoria            ],
      %w[vicky                victoria            ],
      %w[vin                  vincent             ],
      %w[vin                  vincenzo            ],
      %w[vince                vincent             ],
      %w[vince                vinson              ],
      %w[vinnie               vincent             ],
      %w[vinnie               vincenzo            ],
      %w[waldo                oswald              ],
      %w[wendy                gwendolyn           ],
      %w[wilber               gilbert             ],
      %w[will                 wilbur              ],
      %w[will                 william             ],
      %w[will                 wilson              ],
      %w[willie               wilbur              ],
      %w[willie               william             ],
      %w[willie               wilson              ],
      %w[wilma                wilhelmina          ],
      %w[winnie               winnifred           ],
      %w[winny                winnifred           ],
      %w[woody                elwood              ],
      %w[zach                 zachariah           ],
    ]
    @short_to_long = {}
    @long_to_short = {}
    equivalencies.each do |equivalency|
      @short_to_long[equivalency[0]] ||= []
      @short_to_long[equivalency[0]] << equivalency[1]

      @long_to_short[equivalency[1]] ||= []
      @long_to_short[equivalency[1]] << equivalency[0]
    end
  end
end
