Created
March 22, 2013 19:02
-
-
Save acook/5223850 to your computer and use it in GitHub Desktop.
PigLatin Translator!
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
#!/usr/bin/env ruby | |
# Translates a text file to Pig Latin! | |
class PigLatin | |
def initialize filename = nil | |
@filename = filename | |
end | |
attr :filename | |
def translate! | |
ilefay filename | |
end | |
def ilefay file | |
lines = String.new | |
IO.foreach file do |line| | |
lines << inelay(line) | |
end | |
lines | |
end | |
def inelay line | |
line.split(' ').map do |word| | |
ordway word | |
end.join ' ' | |
end | |
def ordway word | |
alpha = word.match(/[a-zA-Z]+/).to_s | |
"#{alpha[1..-1]}#{alpha[0]}ay" | |
end | |
end | |
def self.usage | |
puts "usage : #{$0} path/to/file.txt" | |
end | |
translator = PigLatin.new ARGV.first || usage | |
puts translator.translate! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment