repl.it
@anonymous/

DarkseagreenBonyJaeger

Ruby

No description

fork
loading
Files
  • main.rb
main.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
f=->s{q=->n,c{n.find{|x|x=~/^ ?#{c}/i}||''};e='espresso'
([->c{c>''?(c==?X?'de':c['/2']?'half-':c[?1]?'one-third-':'two-thirds-')+'caf':c},->c{c.sub(/(\d*)(.)?/){i=$1.to_i;(i>0?i<6?%w"0 sing doub trip quadrup quintup"[i]+'le':$1+'-tuple':$1)+($2?' '+q[%w"short tall grande venti",$2]:'')}},->c{c.gsub(/(\d*)(\w)/){i=$1.to_i;n=%w"0 one two three four five six seven eight nine ten eleven twelve thir four fif";n+=n[6..9]<<'twenty';(i>0?n[i]+(i>12&&i<20?'teen ':' '):$1)+q[%w"vanilla caramel mocha hazelnut",$2]}},->c{{?%=>'two-percent','Wh'=>'whole-milk',?N=>'skim',?B=>'breve'}[c]||''},->c{c.gsub(/(x|-)?(\w+)/){({?x=>'extra ',?-=>'no '}[$1]||'')+q[%w"foam whip"+%w"caramel mocha".map{|x|x+' drizzle'},$2[0]]}},->c{c.gsub(/CM|CP|./){{'CP'=>' con pana','CM'=>'caramel'+m=' macchiato'}[$&]||q[%w"americano latte cappuccino"<<m<<e,$&]}}].zip(s.split ?,).map{|a,b|a[b]}-['']).join(' ').sub(/(single|double)(?=.*#{e})/){q[%w"solo doppio",$&[0]]}.sub /o #{e}$/,'o'}

puts f[",3G,V,Wh,,L"]
puts f["X,2T,,N,,L"]
puts f["1/2,V,,,,CM"]
puts f["2/3,3V,3V,B,WC,L"]
puts f[",G,,,xCR,CM"]
puts f["X,4T,2M 2C,B,xWC -F xM,C"]
puts f[",2,1V,B,,EM"]
puts f[",1,,,,E"]
puts f[",2,,,,E"]
puts f[",3,,,,E"]
ruby 2.5.5p157 (2019-03-15 revision 67260) [x86_64-linux]