forked from CSCI305/csci305-ruby-lab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ruby_lab.rb
executable file
·48 lines (38 loc) · 903 Bytes
/
ruby_lab.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/ruby
###############################################################
#
# CSCI 305 - Ruby Programming Lab
#
# <firstname> <lastname>
# <email-address>
#
###############################################################
$bigrams = Hash.new # The Bigram data structure
$name = "<firstname> <lastname>"
# function to process each line of a file and extract the song titles
def process_file(file_name)
puts "Processing File.... "
begin
IO.foreach(file_name) do |line|
# do something for each line
end
puts "Finished. Bigram model built.\n"
rescue
STDERR.puts "Could not open file"
exit 4
end
end
# Executes the program
def main_loop()
puts "CSCI 305 Ruby Lab submitted by #{$name}"
if ARGV.length < 1
puts "You must specify the file name as the argument."
exit 4
end
# process the file
process_file(ARGV[0])
# Get user input
end
if __FILE__==$0
main_loop()
end