Skip to content

Commit 34ffd0a

Browse files
committed
Parse and cache all years of clinical law rankings
1 parent 02d4c61 commit 34ffd0a

File tree

10 files changed

+17811
-22
lines changed

10 files changed

+17811
-22
lines changed

lib/us_news_rankings/category.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ def html_dir
1515
end
1616

1717
def pages
18-
source_urls.each_with_index.map{|url, number| UsNewsRankings::Page.new({
18+
source_urls.each_with_index.map{|url, i| UsNewsRankings::Page.new({
1919
category: self,
2020
url: url,
21-
number: number + 1
21+
number: i + 1
2222
})}
2323
end
2424

@@ -31,7 +31,10 @@ def extract_rankings
3131
extracted_rankings = []
3232
pages.each do |page|
3333
page.table_rows.each do |row|
34-
ranking = UsNewsRankings::Education::GraduateSchools::LawClinical::Ranking.new(row)
34+
ranking = UsNewsRankings::Education::GraduateSchools::LawClinical::Ranking.new({
35+
year: year,
36+
row: row
37+
})
3538
extracted_rankings << ranking.to_h if ranking.ranked?
3639
end
3740
end

lib/us_news_rankings/education/graduate_schools/law_clinical/ranking.rb

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,23 @@ module Education
33
module GraduateSchools
44
module LawClinical
55
class Ranking < UsNewsRankings::Ranking
6+
def rank_selector
7+
case year
8+
when 2014, 2013, 2012
9+
return ".rankings-score"
10+
else
11+
return ".rankscore-bronze"
12+
end
13+
end
14+
15+
def rank
16+
@rank || row.at_css(rank_selector).text.strip.gsub("#","").gsub("Tie","")
17+
end
18+
19+
def tie?
20+
row.at_css(rank_selector).text.include?("Tie")
21+
end
22+
623
def tuition
724
row.at_css(".search_tuition").text.strip #.gsub(" per year (full-time)","")
825
end
@@ -14,7 +31,7 @@ def enrollment
1431
def to_h
1532
{
1633
rank: rank.to_i, # assumes school is ranked
17-
tie: tie,
34+
tie: tie?,
1835
school_name: school_name,
1936
school_city: school_city,
2037
tuition: tuition,

lib/us_news_rankings/ranking.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22

33
module UsNewsRankings
44
class Ranking
5-
attr_reader :row
5+
attr_reader :year, :row
66

7+
# @param year [Integer] the rankings year
78
# @param row [Nokogiri::XML::Element] a rankings table row ("tr") element
8-
def initialize(row)
9+
def initialize(year:, row:)
10+
@year = year
911
@row = row
1012
end
1113

1214
def rank
13-
@rank || row.at_css(".rankscore-bronze").text.strip.gsub("#","").gsub("Tie","")
15+
raise "Oh, please implement #rank on the child class."
1416
end
1517

1618
def ranked?
@@ -29,7 +31,7 @@ def school_city
2931
end
3032

3133
def tie
32-
row.at_css(".rankscore-bronze").text.include?("Tie")
34+
raise "Oh, please implement #tie on the child class."
3335
end
3436

3537
def to_h

spec/category_spec.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
RSpec.describe UsNewsRankings::Category do
2-
describe "#rankings" do
2+
describe "#source_urls" do
33
let(:category){ described_class.new(2017) }
44

55
it "should be implemented in a child class" do
6-
expect{category.rankings}.to raise_error("please implement #rankings on the child class")
6+
expect{category.source_urls}.to raise_error("Oh, please implement #source_urls on the child class.")
7+
end
8+
end
9+
10+
describe "#html_dir" do
11+
let(:category){ described_class.new(2017) }
12+
13+
it "should be implemented in a child class" do
14+
expect{category.html_dir}.to raise_error("Oh, please implement #html_dir on the child class.")
715
end
816
end
917
end

spec/education/graduate_schools/law_clinical/category_spec.rb

Lines changed: 109 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,118 @@
88
end
99

1010
describe "#rankings" do
11-
let(:category){ described_class.new(2017) }
11+
describe "for 2017" do
12+
let(:category){ described_class.new(2017) }
13+
14+
it "should return a list of ranked schools" do
15+
expect(category.rankings.count).to eql(11)
16+
end
17+
18+
it "should contain the expected rankings" do
19+
expect(category.rankings.first).to eql({
20+
:rank=>1,
21+
:tie=>false,
22+
:school_name=>"Georgetown University",
23+
:school_city=>"Washington, DC",
24+
:tuition=>"$57,576 per year (full-time)",
25+
:enrollment=>"1,721"
26+
})
27+
end
28+
end
29+
30+
describe "for 2016" do
31+
let(:category){ described_class.new(2016) }
32+
33+
it "should return a list of ranked schools" do
34+
expect(category.rankings.count).to eql(11)
35+
end
36+
37+
it "should contain the expected rankings" do
38+
expect(category.rankings.first).to eql({
39+
:rank=>1,
40+
:tie=>false,
41+
:school_name=>"Georgetown University",
42+
:school_city=>"Washington, DC",
43+
:tuition=>"$55,255 per year (full-time)",
44+
:enrollment=>"1,725"
45+
})
46+
end
47+
end
48+
49+
describe "for 2015" do
50+
let(:category){ described_class.new(2015) }
51+
52+
it "should return a list of ranked schools" do
53+
expect(category.rankings.count).to eql(12)
54+
end
1255

13-
it "should return a list of ranked schools" do
14-
expect(category.rankings.count).to eql(11)
56+
it "should contain the expected rankings" do
57+
expect(category.rankings.first).to eql({
58+
:rank=>1,
59+
:tie=>false,
60+
:school_name=>"Georgetown University",
61+
:school_city=>"Washington, DC",
62+
:tuition=>"$53,130 per year (full-time)",
63+
:enrollment=>"1,719"
64+
})
65+
end
1566
end
1667

17-
it "should contain the expected rankings" do
18-
expect(category.rankings.first).to eql({
19-
:rank=>1,
20-
:tie=>false,
21-
:school_name=>"Georgetown University",
22-
:school_city=>"Washington, DC",
23-
:tuition=>"$57,576 per year (full-time)",
24-
:enrollment=>"1,721"
25-
})
68+
describe "for 2014" do
69+
let(:category){ described_class.new(2014) }
70+
71+
it "should return a list of ranked schools" do
72+
expect(category.rankings.count).to eql(11)
73+
end
74+
75+
it "should contain the expected rankings" do
76+
expect(category.rankings.first).to eql({
77+
:rank=>1,
78+
:tie=>false,
79+
:school_name=>"Georgetown University",
80+
:school_city=>"Washington, DC",
81+
:tuition=>"$50,890 per year (full-time)",
82+
:enrollment=>"1,694"
83+
})
84+
end
85+
end
86+
87+
describe "for 2013" do
88+
let(:category){ described_class.new(2013) }
89+
90+
it "should return a list of ranked schools" do
91+
expect(category.rankings.count).to eql(11)
92+
end
93+
94+
it "should contain the expected rankings" do
95+
expect(category.rankings.first).to eql({
96+
:rank=>1,
97+
:tie=>false,
98+
:school_name=>"Georgetown University",
99+
:school_city=>"Washington, DC",
100+
:tuition=>"$48,835 per year (full-time)",
101+
:enrollment=>"1,683"
102+
})
103+
end
104+
end
105+
106+
describe "for 2012" do
107+
let(:category){ described_class.new(2012) }
108+
109+
it "should return a list of ranked schools" do
110+
expect(category.rankings.count).to eql(11)
111+
end
112+
113+
it "should contain the expected rankings" do
114+
expect(category.rankings.first).to eql({
115+
:rank=>1,
116+
:tie=>false,
117+
:school_name=>"Georgetown University",
118+
:school_city=>"Washington, DC",
119+
:tuition=>"Full-time: $46,865 per year",
120+
:enrollment=>"1,671"
121+
})
122+
end
26123
end
27124
end
28125
end

0 commit comments

Comments
 (0)