Skip to content

Commit 55c210c

Browse files
committed
Merge pull request #1 from bad6e/refactor_names_2
Refactor names 2
2 parents 58ff27c + db1e326 commit 55c210c

File tree

4 files changed

+28
-46
lines changed

4 files changed

+28
-46
lines changed

app/controllers/application_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ class ApplicationController < ActionController::Base
55

66
require 'nokogiri'
77
require 'open-uri'
8+
89
end
Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,6 @@
11
class WelcomeController < ApplicationController
22

33
def index
4-
urls = ["https://github.com/bad6e",
5-
"https://github.com/roseak",
6-
"https://github.com/mcschatz",
7-
"https://github.com/travishaby",
8-
"https://github.com/Jpease1020",
9-
"https://github.com/jphoenix86",
10-
"https://github.com/HoffsMH",
11-
"https://github.com/MowAlon",
12-
"https://github.com/russelleh",
13-
"https://github.com/jbrr",
14-
"https://github.com/rasensio1",
15-
"https://github.com/selfup",
16-
"https://github.com/dastinnette",
17-
"https://github.com/mbburch",
18-
"https://github.com/Kealii",
19-
"https://github.com/Unsafepond",
20-
"https://github.com/ChrisCenatie",
21-
"https://github.com/adamki",
22-
"https://github.com/plato721",
23-
"https://github.com/Egogre"
24-
]
25-
26-
text = urls.map do |url|
27-
Nokogiri::HTML(open(url)).at_css(".vcard-fullname").text.strip
28-
end
29-
30-
text1 = urls.map do |url|
31-
Nokogiri::HTML(open(url)).at_css(".contrib-number").text.gsub("total","").to_i
32-
end
33-
34-
join = text.zip(text1)
35-
@group = join.sort{|a,b| b[1] <=> a[1]}
4+
@group = Welcome.new.sort
365
end
376
end

app/helpers/application_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
module ApplicationHelper
2-
end
2+
end

app/models/welcome.rb

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class Welcome
22

3-
def self.open_pages
4-
urls = ["https://github.com/bad6e",
3+
def initialize
4+
@urls =["https://github.com/bad6e",
55
"https://github.com/roseak",
66
"https://github.com/mcschatz",
77
"https://github.com/travishaby",
@@ -13,22 +13,34 @@ def self.open_pages
1313
"https://github.com/jbrr",
1414
"https://github.com/rasensio1",
1515
"https://github.com/selfup",
16-
"https://github.com/dastinnette"
17-
]
18-
19-
text = urls.map do |url|
20-
Nokogiri::HTML(open(url)).at_css
21-
end
22-
16+
"https://github.com/dastinnette",
17+
"https://github.com/mbburch",
18+
"https://github.com/Kealii",
19+
"https://github.com/Unsafepond",
20+
"https://github.com/ChrisCenatie",
21+
"https://github.com/adamki",
22+
"https://github.com/plato721",
23+
"https://github.com/Egogre"]
24+
end
2325

26+
def sort
27+
join_arrays = get_names.zip(get_count)
28+
join_arrays.sort{|a,b| b[1] <=> a[1]}
2429
end
2530

26-
def self.name
27-
@data.at_css(".vcard-fullname").text.strip
31+
def get_names
32+
@urls.map do |url|
33+
open_url(url).at_css(".vcard-fullname").text.strip
34+
end
2835
end
2936

30-
def counter
31-
@data.at_css(".contrib-number").text.strip
37+
def get_count
38+
@urls.map do |url|
39+
open_url(url).at_css(".contrib-number").text.gsub("total","").to_i
40+
end
3241
end
3342

43+
def open_url(url)
44+
Nokogiri::HTML(open(url))
45+
end
3446
end

0 commit comments

Comments
 (0)