unm 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/unm/version.rb +1 -1
- data/lib/unm.rb +49 -29
- data/unm-0.0.7.gem +0 -0
- metadata +3 -3
- data/unm-0.0.5.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 271a492c1a771289fbd60feff42a1bef2484ef3e
|
4
|
+
data.tar.gz: c12cb3e3896b0ca49f2d8122fc061f15cd81c4ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd2b11c897fbe49e804dc51f9dc58f39056c4af1d0c5506c94041e34b3869270a2ac20da748ffec70f898f478b132be1d3e2cdecbbb43b4ca827446c5f7ad232
|
7
|
+
data.tar.gz: 67e293e730c277f0fd4a3fcc591a2ce0789ea5e512f4ecb55f4d43d57a99018526b0f91dd8f3629e6708823f23f3d5af39b692eb7ed1f0325a3e421154ed49b8
|
data/lib/unm/version.rb
CHANGED
data/lib/unm.rb
CHANGED
@@ -5,12 +5,12 @@ require 'singleton'
|
|
5
5
|
module Unm
|
6
6
|
|
7
7
|
class Calendar
|
8
|
-
BaseUrl = URI
|
8
|
+
BaseUrl = URI('http://unmevents.unm.edu/Eventlist.aspx')
|
9
9
|
Formats = ["CSV", "ICAL", "XML"]
|
10
10
|
|
11
11
|
def initialize(from_date, to_date, format = "CSV")
|
12
|
-
@from_date, @to_date = check_date
|
13
|
-
@format = check_format
|
12
|
+
@from_date, @to_date = check_date(from_date, to_date)
|
13
|
+
@format = check_format(format)
|
14
14
|
end
|
15
15
|
|
16
16
|
def get
|
@@ -21,19 +21,19 @@ module Unm
|
|
21
21
|
private
|
22
22
|
|
23
23
|
def build_params
|
24
|
-
@url = URI
|
24
|
+
@url = URI(BaseUrl)
|
25
25
|
@url.query = URI.encode_www_form [["download", "download"],
|
26
26
|
["fromdate", @from_date],
|
27
27
|
["todate" , @to_date ],
|
28
28
|
["dlType" , @format ]]
|
29
29
|
end
|
30
30
|
|
31
|
-
def check_format
|
31
|
+
def check_format(format)
|
32
32
|
raise "Unknown format" unless Formats.include? format.upcase
|
33
33
|
format.upcase
|
34
34
|
end
|
35
35
|
|
36
|
-
def check_date
|
36
|
+
def check_date(from_date, to_date)
|
37
37
|
raise "Please do not span more than one year" if to_date - from_date > 365
|
38
38
|
raise "to_date must be after from_date" if from_date > to_date
|
39
39
|
[from_date.strftime("%m%d%Y"), to_date.strftime("%m%d%Y")]
|
@@ -45,36 +45,56 @@ module Unm
|
|
45
45
|
|
46
46
|
include Singleton
|
47
47
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
48
|
+
class << self
|
49
|
+
|
50
|
+
def get
|
51
|
+
return @catalog if @catalog
|
52
|
+
subjects = HTTParty.get("http://catalog.unm.edu/catalogs/2015-2016/subjects-and-courses.xml")["data"]["subjects"]["subject"]
|
53
|
+
@catalog = subjects.map do |subject|
|
54
|
+
courses = subject["course"]
|
55
|
+
name = subject["subjectName"]
|
56
|
+
{ name => [courses].flatten.map do |course|
|
57
|
+
course_name = name + " " + course["name"]
|
58
|
+
course_page = Nokogiri::HTML.parse(HTTParty.get(URI.escape course["path"])) rescue course["path"]
|
59
|
+
description = course_page.css('.content > p').first.text rescue "Error loading description. Check #{course["path"]}."
|
60
|
+
prerequisites = find_prerequisites(course_page) rescue "Error loading prerequisites. Check #{course["path"]}."
|
61
|
+
hours = course_page.css('b').text.match(/\(\D*(\d).*\)/)[1].to_i rescue "Error loading hours. Check #{course["path"]}."
|
62
|
+
{ "name" => course_name, "description" => description, "prerequisites" => prerequisites, "hours" => hours }
|
63
|
+
end }
|
64
|
+
end
|
62
65
|
end
|
63
|
-
end
|
64
66
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
67
|
+
def find_prerequisites(site)
|
68
|
+
start = site.css("hr").first
|
69
|
+
finish = site.css("hr")[1]
|
70
|
+
prerequisites = []
|
71
|
+
until start == finish
|
72
|
+
prerequisites << start.text.split("- ").last if start.css('a').any?
|
73
|
+
start = start.next_element
|
74
|
+
end
|
75
|
+
prerequisites
|
72
76
|
end
|
73
|
-
|
77
|
+
|
74
78
|
end
|
75
79
|
|
76
80
|
private_class_method :find_prerequisites
|
77
81
|
|
78
82
|
end
|
79
83
|
|
84
|
+
class Directory
|
85
|
+
|
86
|
+
include Singleton
|
87
|
+
|
88
|
+
BaseUrl = 'http://directory.unm.edu/index.php'
|
89
|
+
|
90
|
+
def self.find(search_term, field = 'uid', exact: false)
|
91
|
+
page = HTTParty.post(BaseUrl, body: { search_other_name: field, search_other_value: search_term })
|
92
|
+
results = Nokogiri::HTML.parse(page).css('tr').drop(1).map do |row|
|
93
|
+
Hash[[:name, :title, :contact].zip(row.css('td').map { |cell| cell.children.map(&:text).reject(&:empty?) })]
|
94
|
+
end
|
95
|
+
exact ? results.find { |result| result[:contact].any? { |email| email.split('@').first == search_term } } : results
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
|
80
100
|
end
|
data/unm-0.0.7.gem
ADDED
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ricardo Piro-Rael
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,7 +80,7 @@ files:
|
|
80
80
|
- Rakefile
|
81
81
|
- lib/unm.rb
|
82
82
|
- lib/unm/version.rb
|
83
|
-
- unm-0.0.
|
83
|
+
- unm-0.0.7.gem
|
84
84
|
- unm.gemspec
|
85
85
|
homepage: ''
|
86
86
|
licenses:
|
data/unm-0.0.5.gem
DELETED
Binary file
|