Skip to content

Instantly share code, notes, and snippets.

@rafaelmedeirospb83
Created June 14, 2017 21:36
Show Gist options
  • Save rafaelmedeirospb83/497be13d322f3656978de16fffbd6ba8 to your computer and use it in GitHub Desktop.
Save rafaelmedeirospb83/497be13d322f3656978de16fffbd6ba8 to your computer and use it in GitHub Desktop.
Prova-Ruby-Rafael-Figueirêdo-de-Medeiros
require 'json'
class Util
def self.load_json(nome)
JSON.parse(File.read(nome))
end
end
class UAI
def initialize
@subjects = Util.load_json('subjects.json')
end
def list_teachers(course_name: nil)
result = []
if (course_name)==nil
@subjects.each{|subject|
if (subject['instructor']['name']).include?("-")
aux =[]
aux = subject['instructor']['name'].split(" - ")
result.push aux.first
else
result.push subject['instructor']['name']
end
}
end
if (course_name)!=nil
@subjects.each{|subject|
if (subject['course'])==(course_name)
if (subject['instructor']['name']).include?("-")
aux =[]
aux = subject['instructor']['name'].split(" - ")
result.push aux.first
else
result.push subject['instructor']['name']
end
end
}
end
return result.uniq.sort
end
def list_courses_involved
result = []
@subjects.each{|subject|
result.push subject['course']
}
result.uniq.sort
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment