Created
January 21, 2012 04:24
-
-
Save AnimaWish/1651280 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class String | |
def initial | |
self[0,1] #gets first character | |
end | |
def twoinitial | |
self[0,2] #gets first two characters | |
end | |
def secondy | |
self[1,1] | |
end | |
end | |
#arrays of things that pig latin cares about | |
vowels = ["a", "e", "i", "o", "u"] | |
consonants = ["b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "q", "r", "s", "t", "v", "w", "x", "y", "z"] | |
punctuation = ["!", "?", ",", "."] | |
particles = ["A", "I", "At", "Or", "On", "The", "Is", "It"] | |
names = ["Jennifer", "Randall", "Kenneth", "Norman", "Sandy", "Helen", "Ronald"] | |
#the actual shit for English -> Pig Latin | |
def piglatin(statement, vowels, consonants, punctuation, particles) | |
translated = statement.split | |
finaltrans = [] | |
b = '' | |
translated.each do |item| | |
naughtypunc = [] | |
if punctuation.include? item[-1] #checks if there's punctuation and saves it in naughtypunc | |
naughtypunc = item.each_char.select {|c| punctuation.include? c } | |
item.sub!(naughtypunc.join,'') | |
end | |
if particles.include? item.downcase.capitalize #stops the loop if it's a particle | |
finaltrans << item | |
next | |
elsif vowels.include? item.initial.downcase | |
a = item | |
elsif item.initial.downcase == "y" and consonants.include? item.secondy.downcase | |
a = item | |
elsif consonants.include? item.initial.downcase | |
naughtyvowel = item.each_char.select {|c| vowels.include? c } | |
firstvowel = item.index(naughtyvowel[0]) | |
b = item[0...firstvowel] | |
a = item[firstvowel..-1] | |
end | |
item = a + "-" + b + "ay" + naughtypunc.join | |
finaltrans << item | |
b = '' | |
end | |
output = finaltrans.join (" ") | |
puts output.capitalize | |
end | |
#method for PL -> E | |
def english(statement, vowels, punctuation, particles) | |
translated = statement.split | |
finaltrans = [] | |
translated.each do |item| | |
splitem = item.split('-') #cuts the word from *ay | |
naughtypunc = [] | |
if punctuation.include? item[-1] #checks if there's punctuation and saves it in naughtypunc | |
naughtypunc = item.each_char.select {|c| punctuation.include? c } | |
item.sub!(naughtypunc.join,'') | |
end | |
if particles.include? item.downcase.capitalize #stops the loop if it's a particle | |
finaltrans << item | |
# next | |
else | |
a = splitem[0] | |
b = splitem[1] | |
if naughtypunc.join.nil? #if there's something in naughtypunc it goes 1 more | |
c = b[0..-3] | |
else | |
d = 3 + naughtypunc.join.length | |
c = b[0..-d] | |
end | |
if vowels.include? c | |
item = a + naughtypunc.join.to_s | |
else | |
item = c + a + naughtypunc.join.to_s | |
end | |
finaltrans << item | |
end | |
end | |
output = finaltrans.join (" ") | |
puts output.capitalize | |
end | |
loop do | |
puts "Welcome to Pig Latin Translator 2000. My name is %s, and I will be your translator today." % names[rand(names.length())] | |
puts "What service would you like today? English to Pig Latin (1) or Pig Latin to English (2)? Q to quit." | |
service = gets.chomp | |
if service == "1" | |
puts "You have selected 'English to Pig Latin'." | |
puts "Please input the phrase you would like translated." | |
print "> " | |
statement = gets.chomp | |
piglatin(statement, vowels, consonants, punctuation, particles) | |
break | |
elsif service == "2" | |
puts "You have selected 'Pig Latin to English'." | |
puts "Input the phrase you would like translated. (Please use hyphens to separate the base word from the pig latin suffix)" | |
print "> " | |
statement = gets.chomp | |
english(statement, vowels, punctuation, particles) | |
break | |
elsif service == "3" | |
puts "--------" | |
puts "I need to fix proper nouns. Paul -> Aul-pay instead of aul-pay" | |
puts "Better case sensitivity. SCRAM -> AM-SCRAY" #maybe have if item.upcase == item then exceptionville blalhalhla | |
puts "--------" | |
woah = gets | |
elsif service.capitalize == "Q" | |
break | |
else | |
puts "Not understood." | |
end | |
end | |
#Where are my pants, woman? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment