Created
May 31, 2014 08:41
-
-
Save babarot/fce004b8ba7776e8c14c 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
#!/usr/bin/env ruby | |
# | |
# NATO phonetic alphabet | |
# | |
def usage | |
puts "Usage: " + File.basename($0) + " num1 [num2]" | |
puts "" | |
puts "num1 - This number expresses an opening in table." | |
puts "num2 - This number expresses number of times in table." | |
puts "When you omit the num2, the practice number of times is regarded only once." | |
puts "POINT TO NOTICE:" | |
puts " It is necessary for num1 and num2 to be greater than 0." | |
puts " num1 has to be greater than 0." | |
puts " In addition, sum (num1 + num2) has to be less than or equal 26." | |
puts "" | |
end | |
## {{{ | |
table = { 1=>"alpha", 2=>"bravo", 3=>"charlie", 4=>"delta", 5=>"echo", 6=>"foxtrot", 7=>"golf", | |
8=>"hotel", 9=>"india", 10=>"juliett", 11=>"kilo", 12=>"lima", 13=>"mike", 14=>"november", | |
15=>"oscar", 16=>"papa", 17=>"quebec", 18=>"romeo", 19=>"sierra", 20=>"tango", 21=>"uniform", | |
22=>"victor", 23=>"whiskey", 24=>"x-ray", 25=>"yankee", 26=>"zulu" } | |
num1 = ARGV[0].to_i | |
if ARGV[1] == nil then | |
num2 = 0 | |
else | |
num2 = ARGV[1].to_i | |
end | |
## }}} | |
if num1 > 26 || num1 == 0 || num1 + num2 >27 then | |
usage | |
exit 1 | |
end | |
if ARGV.size == 1 then | |
if ! File.exist?(table[num1]) then | |
Dir.mkdir(table[num1]) | |
exit 0 | |
else | |
puts table[num1] + ": Already exist" | |
exit 1 | |
end | |
elsif ARGV.size == 2 then | |
num2.times { | |
if ! File.exist?(table[num1]) then | |
Dir.mkdir(table[num1]) | |
else | |
puts table[num1] + ": Already exist" | |
end | |
num1 += 1 | |
} | |
exit 0 | |
else | |
usage | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment