Minor fix for compatibility with Ruby versions that don't understand
[mailvisa.git] / view_scores.rb
blobeae329586e9d34f5bc13d5f73f04a38297cf1d02
1 require 'wordlist'
3 ### Defaults
4 confdir = ENV['HOME'] + '/settings/mailvisa'
5 scorefile = 'scores'
7 usage = 'USAGE: ' + $0 + ' [options]'
9 help = <<EOT
10 Valid options:
12 -c <path>       Look for files in <path> (default: $HOME/settings/mailvisa)
13 -f <path>       Load scores from <path> (default: scores)
14 EOT
16 ## Process command line
17 i = 0
18 while i < ARGV.length
19         case ARGV[i]
20         when '-h'
21                 puts usage
22                 puts "\n" + help
23                 exit
24         when '-c'
25                 i = i + 1
26                 confdir = ARGV[i]
27         when '-f'
28                 i = i + 1
29                 scorefile = ARGV[i]
30         when /^-/
31                 $stderr.puts 'Unknown option: ' + ARGV[i]
32                 $stderr.puts usage
33                 $stderr.puts 'Use "' + $0 + ' -h" for help'
34                 exit 0x80
35         else
36                 scorefile = ARGV[i]
37         end
38         i = i + 1
39 end
41 scorefile = confdir + '/' + scorefile if scorefile.index('/') == nil
43 ## Display scores
44 fh = open scorefile
45 db = load_wordlist fh
46 fh.close
48 db[:words].each do |word,score|
49         puts "#{word}: #{score}"
50 end