You are on page 1of 4

testform3.rb(main):001:0> #!

/usr/bin/ruby
testform3.rb(main):002:0*
testform3.rb(main):003:0* require "uri"
=> true
testform3.rb(main):004:0> require "net/http"
=> true
testform3.rb(main):005:0> require 'rubygems'
=> false
testform3.rb(main):006:0> require 'mechanize'
=> true
testform3.rb(main):007:0>
testform3.rb(main):008:0* tracker = 0
=> 0
testform3.rb(main):009:0> #Consists of the following data in this order:
testform3.rb(main):010:0* # 0 Dept | 1 Subject Name | 2 Activity | 3 Scheduled As |
4 Day |
testform3.rb(main):011:0* # 5 Start Time | 6 End Time | 7 Duration | 8 Location | 9
Capacity
testform3.rb(main):012:0* #Teaching Staff for Activity Teaching Weeks | Status
Desccription
testform3.rb(main):013:0*
testform3.rb(main):014:0* class Timeslot
testform3.rb(main):015:1> attr_accessor :start_time #Singular
testform3.rb(main):016:1> attr_accessor :end_time #Singular
testform3.rb(main):017:1> attr_accessor :days #Multiple
testform3.rb(main):018:1> attr_accessor :weeks #Multiple
testform3.rb(main):019:1> attr_accessor :spaces #Multiple
testform3.rb(main):020:1>
testform3.rb(main):021:1* #Constructor
testform3.rb(main):022:1* #def initialize start_time, end_time
testform3.rb(main):023:1* #string for now
testform3.rb(main):024:1* # @start_time = start_time
testform3.rb(main):025:1* # @end_time = end_time
testform3.rb(main):026:1* # @days = []
testform3.rb(main):027:1* # @spaces = []
testform3.rb(main):028:1* #end
testform3.rb(main):029:1*
testform3.rb(main):030:1* def initialize line
testform3.rb(main):031:2> tracker = 0
testform3.rb(main):032:2> l = line.split("\t")
testform3.rb(main):033:2>
testform3.rb(main):034:2* @start_time = l[6]
testform3.rb(main):035:2> @end_time = l[7]
testform3.rb(main):036:2> @days = l[5]
testform3.rb(main):037:2> @spaces =[]
testform3.rb(main):038:2> @weeks = []
testform3.rb(main):039:2> parse_weeks(l[12])
testform3.rb(main):040:2> parse_spaces(l[9])
testform3.rb(main):041:2> #puts @spaces
testform3.rb(main):042:2*
testform3.rb(main):043:2* end
testform3.rb(main):044:1>
testform3.rb(main):045:1* #Takes string of days, separates by comma, appends to
an array
testform3.rb(main):046:1* def parse_days days_string
testform3.rb(main):047:2> days_string.split(",").each do |day|
testform3.rb(main):048:3* @days << day.strip
testform3.rb(main):049:3> end
testform3.rb(main):050:2> end
testform3.rb(main):051:1>
testform3.rb(main):052:1* #Takes an input of start/end weeks, eg 1-12, populating
array with each
testform3.rb(main):053:1* #individual weeks.
testform3.rb(main):054:1* def parse_weeks weeks_string
testform3.rb(main):055:2> w = weeks_string.split("-")
testform3.rb(main):056:2> if(w.count > 1)
testform3.rb(main):057:3> @weeks = (w[0].to_i..w[1].to_i).to_a
testform3.rb(main):058:3> else
testform3.rb(main):059:3* @weeks << w[0].to_i
testform3.rb(main):060:3> end
testform3.rb(main):061:2>
testform3.rb(main):062:2* end
testform3.rb(main):063:1>
testform3.rb(main):064:1* #Separates all spaces(bulding-room), into their
individual pairing
testform3.rb(main):065:1* def parse_spaces spaces_string
testform3.rb(main):066:2> spaces_string.split(";").each do |single_space|
testform3.rb(main):067:3* @spaces << add_space(single_space)
testform3.rb(main):068:3> end
testform3.rb(main):069:2> end
testform3.rb(main):070:1>
testform3.rb(main):071:1* #Adds a single space
testform3.rb(main):072:1* #Splits the building name and room number into
different attributes
testform3.rb(main):073:1* def add_space space_string
testform3.rb(main):074:2> d = space_string.split("-")
testform3.rb(main):075:2> space = Space.new(d[0],d[1])
testform3.rb(main):076:2> return space
testform3.rb(main):077:2> end
testform3.rb(main):078:1>
testform3.rb(main):079:1* #Just for debug printing
testform3.rb(main):080:1* def timeslot_print
testform3.rb(main):081:2> puts "starts: #{@start_time}"
testform3.rb(main):082:2> puts "ends: #{@end_time}"
testform3.rb(main):083:2> puts "days: #{@days}"
testform3.rb(main):084:2> puts "weeks: #{@weeks}"
testform3.rb(main):085:2> print "locations: #{@spaces}"
testform3.rb(main):086:2> puts " "
testform3.rb(main):087:2> end
testform3.rb(main):088:1>
testform3.rb(main):089:1* end
=> :timeslot_print
testform3.rb(main):090:0>
testform3.rb(main):091:0* class Space
testform3.rb(main):092:1>
testform3.rb(main):093:1* attr_accessor :building #Singular
testform3.rb(main):094:1> attr_accessor :room #Singular
testform3.rb(main):095:1> attr_accessor :LSS_spaces
testform3.rb(main):096:1>
testform3.rb(main):097:1*
testform3.rb(main):098:1*
testform3.rb(main):099:1* @@LSS_spaces =
testform3.rb(main):100:1* ["100 Leicester St",
testform3.rb(main):101:2* "142 Pelham St",
testform3.rb(main):102:2* "200 Berkeley St",
testform3.rb(main):103:2* "198 Berkeley St (The Spot)",
testform3.rb(main):104:2* "200 Berkeley St",
testform3.rb(main):105:2* "207 Bouverie St",
testform3.rb(main):106:2* "757 Swanston St",
testform3.rb(main):107:2* "Alan Gilbert",
testform3.rb(main):108:2* "Alice Hoy",
testform3.rb(main):109:2* "Babel",
testform3.rb(main):110:2* "Baillieu Library",
testform3.rb(main):111:2* "Baldwin Spencer",
testform3.rb(main):112:2* "Biosciences 2 (Botany)",
testform3.rb(main):113:2* "Biosciences 4 (Zoology)",
testform3.rb(main):114:2* "Building 184 (formerly Microbiology)",
testform3.rb(main):115:2* "Burnley",
testform3.rb(main):116:2* "Chemical & Biomolecular Engineering",
testform3.rb(main):117:2* "Chemistry",
testform3.rb(main):118:2* "Creswick",
testform3.rb(main):119:2* "David Caro",
testform3.rb(main):120:2* "Doug McDonell",
testform3.rb(main):121:2* "Electrical and Electronic Engineering",
testform3.rb(main):122:2* "Elisabeth Murdoch",
testform3.rb(main):123:2* "Engineering-B",
testform3.rb(main):124:2* "Engineering-C",
testform3.rb(main):125:2* "ERC",
testform3.rb(main):126:2* "FBE",
testform3.rb(main):127:2* "Federation Hall",
testform3.rb(main):128:2* "Frank Tate",
testform3.rb(main):129:2* "FVAS",
testform3.rb(main):130:2* "John Medley",
testform3.rb(main):131:2* "234 Queensberry St",
testform3.rb(main):132:2* "Kwong Lee Dow",
testform3.rb(main):133:2* "Kwong Lee Dow (formerly 234 Queensberry St)",
testform3.rb(main):134:2* "Law",
testform3.rb(main):135:2* "McCoy",
testform3.rb(main):136:2* "Medical",
testform3.rb(main):137:2* "MSD",
testform3.rb(main):138:2* "Old Arts",
testform3.rb(main):139:2* "Old Engineering",
testform3.rb(main):140:2* "Old Geology",
testform3.rb(main):141:2* "Old Metallurgy",
testform3.rb(main):142:2* "Old Physics",
testform3.rb(main):143:2* "Old Quad",
testform3.rb(main):144:2* "Physics South",
testform3.rb(main):145:2* "Redmond Barry",
testform3.rb(main):146:2* "Richard Berry",
testform3.rb(main):147:2* "Sidney Myer Asia Centre",
testform3.rb(main):148:2* "Veterinary Science",
testform3.rb(main):149:2* "VRI",
testform3.rb(main):150:2* "Werribee",
testform3.rb(main):151:2* "Wilson Hall"
testform3.rb(main):152:2>
testform3.rb(main):153:2* ]
testform3.rb(main):154:1>
testform3.rb(main):155:1* def initialize building, room
testform3.rb(main):156:2> #@building = building.strip
testform3.rb(main):157:2* #@room = room.strip
testform3.rb(main):158:2* #puts "#{building} - #{room}"
testform3.rb(main):159:2*
testform3.rb(main):160:2* #This check ensures it's only LSS buildings
(individual spaces are checked later)
testform3.rb(main):161:2* if @@LSS_spaces.include? building
testform3.rb(main):162:3> @building = building
testform3.rb(main):163:3> @room = room
testform3.rb(main):164:3> end
testform3.rb(main):165:2> end
testform3.rb(main):166:1>
testform3.rb(main):167:1* end
=> :initialize
testform3.rb(main):168:0>
testform3.rb(main):169:0*
testform3.rb(main):170:0* index = 0
=> 0
testform3.rb(main):171:0> File.open('timetable15sep.txt').each do |line|
testform3.rb(main):172:1* max = 150
testform3.rb(main):173:1> t = Timeslot.new(line)
testform3.rb(main):174:1> if(t.Space.building != nil)
testform3.rb(main):175:2> t.timeslot_print
testform3.rb(main):176:2> end
testform3.rb(main):177:1>
testform3.rb(main):178:1* end
NoMethodError: undefined method `Space' for #<Timeslot:0x007fb1373a0e18>
from testform3.rb:174:in `block in irb_binding'
from testform3.rb:171:in `each'
from testform3.rb:171
from /usr/local/bin/irb:11:in `<main>'
testform3.rb(main):179:0>
testform3.rb(main):180:0*
testform3.rb(main):181:0*
testform3.rb(main):182:0*
testform3.rb(main):183:0*
testform3.rb(main):184:0* nil
=> nil
testform3.rb(main):185:0>

You might also like