Ruby Source Code: fread.rb
#!/usr/bin/ruby
require 'cgi'
require './common'
#----------------------------------------------------------
# The Web Language Project
# Mark Brautigam
# May-June 2015
# http://www.mixed-up.com/markb/
#----------------------------------------------------------
cgi = CGI.new
puts cgi.header
headers1()
headers2()
print sidebarX("ruby", "fread", "rb")
print %q(
<div id="content">
<h2>Ruby: Display File Data Contents</h2>
<table class='results'>
<tr><th>College</th><th>Dept.</th><th>Course</th><th>Description</th><th>Edit</th></tr>
)
#----------------------------------------------------
# The main Ruby code is here.
#----------------------------------------------------
f = File.new('../data/courses.txt', 'r')
courses = f.readlines()
ncourses = courses.count
for i in (0..ncourses-1)
coursedata = courses[i].split("|")
print "<tr>\n"
printf("<td>%s</td>", coursedata[0])
printf("<td>%s</td>", coursedata[1])
printf("<td>%s</td>", coursedata[2])
printf("<td>%s</td>", coursedata[3])
printf("<td><a href='fedit.rb?id=%d'><img src='../images/pencil.svg' /></a></td>\n", (i))
print "</tr>\n"
end
#----------------------------------------------------
print %q(
</table>
<p><a href='fwrite.rb'>Write to this file »</a></p>
<p><a href='source.rb?f=2'>Show Ruby source code »</a>
</div>
)
footers()