RosettaCodeData/Task/Abbreviations-easy/Ruby/abbreviations-easy.rb

17 lines
321 B
Ruby
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
#!/usr/bin/env ruby
cmd_table = File.read(ARGV[0]).split
user_str = File.read(ARGV[1]).split
user_str.each do |abbr|
candidate = cmd_table.find do |cmd|
cmd.count('A-Z') <= abbr.length && abbr.casecmp(cmd[0...abbr.length]).zero?
end
print candidate.nil? ? '*error*' : candidate.upcase
print ' '
end
puts