50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/unm.rb', line 50
def get(catalog_year = 2017)
return @catalog if @catalog
catalog_year = catalog_year.to_s << "-" << catalog_year.next.to_s
subjects = HTTParty.get("http://catalog.unm.edu/catalogs/#{catalog_year}/subjects-and-courses.xml")["data"]["subjects"]["subject"]
@catalog = subjects.map do |subject|
courses = subject["course"]
name = subject["subjectName"]
{ name => [courses].flatten.map do |course|
course_name = name + " " + course["name"]
course_page = Nokogiri::HTML.parse(HTTParty.get(URI.escape course["path"])) rescue course["path"]
course_title = course_page.css('h1').first.text rescue "Error loading course title. Check #{course['path']}."
description = course_page.css('.content > p').first.text rescue "Error loading description. Check #{course["path"]}."
prerequisites = find_prerequisites(course_page) rescue "Error loading prerequisites. Check #{course["path"]}."
hours = course_page.css('b').text.match(/\(\D*(\d).*\)/)[1].to_i rescue "Error loading hours. Check #{course["path"]}."
{ "name" => course_name, "title" => course_title, "description" => description, "prerequisites" => prerequisites, "hours" => hours }
end }
end
end
|