Created
June 14, 2017 21:36
-
-
Save rafaelmedeirospb83/497be13d322f3656978de16fffbd6ba8 to your computer and use it in GitHub Desktop.
Prova-Ruby-Rafael-Figueirêdo-de-Medeiros
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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