Skip to content

Instantly share code, notes, and snippets.

@benkoshy
Last active April 4, 2017 22:28
Show Gist options
  • Save benkoshy/f7425c183bc2bf71979fb3e36138f2ce to your computer and use it in GitHub Desktop.
Save benkoshy/f7425c183bc2bf71979fb3e36138f2ce to your computer and use it in GitHub Desktop.
require_relative 'data_values' #the strings of facts for each city are stored in an array here
 #any string in the hash is just a 'fill-in' for cities without facts yet.
city_hash = {  
:Portland => [FactPort0 , FactPort1 , FactPort2, FactPort3 , FactPort4],
:SanFrancisco => [FactSF0 , FactSF1 , FactSF2, FactSF3 , FactSF4] ,
:SantaFe => [FactSAFE0 , FactSAFE1 , FactSAFE2, FactSAFE3 , FactSAFE4]   ,
:Tokyo => [FactTKY0 , FactTKY1 , FactTKY2, FactTKY3 , FactTKY4] ,
:Seattle => [FactSEA0 , FactSEA1 , FactSEA2, FactSEA3 , FactSEA4] ,
:Vancouver => [FactVAN0 , FactVAN1 , FactVAN2, FactVAN3 , FactVAN4] ,
:LakeTahoe => [FactTAH0 , FactTAH1 , FactTAH2, FactTAH3 , FactTAH4] ,
:Cambridge => [FactCAM0 , FactCAM1 , FactCAM2, FactCAM3 , FactCAM4] ,
:Berlin => [FactBER0 , FactBER1 , FactBER2, FactBER3 , FactBER4] ,
:SantaClara => [FactSC0 , FactSC1 , FactSC2, FactSC3 , FactSC4] ,
:Miami => [FactMIA0 , FactMIA1 , FactMIA2, FactMIA3 , FactMIA4] ,
:Beijing => [FactBEI0 , FactBEI1 , FactBEI2, FactBEI3 , FactBEI4] ,
:LosAngeles => [FactLA0 , FactLA1 , FactLA2, FactLA3 , FactLA4] ,
:Prague => [FactPRA0 , FactPRA1 , FactPRA2, FactPRA3 , FactPRA4] ,
:Austin => [FactAUSTX0 , FactAUSTX1 , FactAUSTX2, FactAUSTX3 ,     FactAUSTX4] ,
:Durham => ["FactDUR0" , "FactDUR1" , "FactDUR2", "FactDUR3" , "FactDUR4"] ,
:Seville => ["FactSEV0" , "FactSEV1" , "FactSEV2", "FactSEV3" , "FactSEV4"] ,
:Yokohama => ["FactYOKO0" , "FactYOKO1" , "FactYOKO2", "FactYOKO3" , "FactYOKO4"] ,
:Bengaluru => ["FactBENG0" , "FactBENG1" , "FactBENG2", "FactBENG3" , "FactBENG4"] ,
:SanJose => ["FactSJ0" , "FactSJ1" , "FactSJ2", "FactSJ3" , "FactSJ4"]
 }

list = city_hash.keys.sort
error_message = "\n Factbot didn't understand. Check your typing and   try again. \n"
end_prompt = "Thanks for using fact_bot!"

puts "Welcome to fact_bot! fact_bot knows some facts about the     following cities: \n "
puts list << "\n"
#none of the regex's are complete, most aren't 'functional' mainly filler!
loop do
puts "| Type any city listed to see facts |'exit' to leave | 'list' to    view cities |  "
gets
case $_.downcase
when /^exit/
  break
when /^list/
  $_ = list
when /aus.+|.+tin|.+ust.+|.+sti.+|a.+t.+in/                   #austin
  $_ = :Austin                                              
when /ji/                                                     #beijing
  $_ = :Beijing
when /al|b.n|ga|lu|ru/                                           #bengaluru
  $_ = :Bengaluru
when /b.r|rl/                                                 #berlin
  $_ = :Berlin
when /ca|^c|dg|mb|ri/                                         #cambridge
  $_ = :Cambridge    
when /du|m$|rh/                                               #durham
  $_ = :Durham
when  /ah|ak|et|ho|ke|oe/                                     #lake tahoe
  $_ = :LakeTahoe
when /s$/                                                     #los angeles
  $_ = :LosAngeles
when /m.+m/                                                   #miami
  $_ = :Miami    
when /nd|or|po|p.+d|rt/                                       #portland
  $_ = :Portland
when /ag|gu|pr|p.+e/                                          #prague
  $_ = :Prague 
when /c.+c|fr|nf|n.f|sc|sf/                                   #san francisco
  $_ = :SanFrancisco
when /jo|nj|n.j/                                              #san jose
  $_ = :SanJose
when /ac|ar|cl/                                               #santa clara
  $_ = :SantaClara
when /af|fe/                                                  #santa fe
  $_ = :SantaFe
when /at|sea|tt/                                              #seattle
  $_ = :Seattle
when  /s.+v/                                                  #seville
  $_ = :Seville
when /ky|to/                                                  #tokyo
  $_ = :Tokyo
when /r$/                                                     #vancouver
  $_ = :Vancouver
when /ko|ma/                                                  #yokohama
  $_ = :Yokohama
else
  $_ = error_message
end
  if $_ == error_message
    puts error_message
  elsif $_ == list
    puts list
  else
    puts "\n Random #{$_} Fact: #{city_hash[$_].sample(1)} \n\n" 
  end
end
puts end_prompt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment