Skip to content

Commit 8d9f357

Browse files
committed
Merge pull request #3 from bad6e/add_bd
Add bd
2 parents 55c210c + 2e9cba8 commit 8d9f357

File tree

12 files changed

+74
-48
lines changed

12 files changed

+74
-48
lines changed

app/controllers/application_controller.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,4 @@ class ApplicationController < ActionController::Base
22
# Prevent CSRF attacks by raising an exception.
33
# For APIs, you may want to use :null_session instead.
44
protect_from_forgery with: :exception
5-
6-
require 'nokogiri'
7-
require 'open-uri'
8-
95
end
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class StatsController < ApplicationController
2+
3+
def index
4+
@stats = Stat.order(commits: :desc)
5+
end
6+
7+
private
8+
9+
def commit_params
10+
params.require(:record).permit(:name, :commits)
11+
end
12+
end

app/controllers/welcome_controller.rb

Lines changed: 0 additions & 6 deletions
This file was deleted.

app/helpers/welcome_helper.rb

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
class Welcome
2-
3-
def initialize
4-
@urls =["https://github.com/bad6e",
1+
module GlobalConstants
2+
URLS = ["https://github.com/bad6e",
53
"https://github.com/roseak",
64
"https://github.com/mcschatz",
75
"https://github.com/travishaby",
@@ -21,26 +19,4 @@ def initialize
2119
"https://github.com/adamki",
2220
"https://github.com/plato721",
2321
"https://github.com/Egogre"]
24-
end
25-
26-
def sort
27-
join_arrays = get_names.zip(get_count)
28-
join_arrays.sort{|a,b| b[1] <=> a[1]}
29-
end
30-
31-
def get_names
32-
@urls.map do |url|
33-
open_url(url).at_css(".vcard-fullname").text.strip
34-
end
35-
end
36-
37-
def get_count
38-
@urls.map do |url|
39-
open_url(url).at_css(".contrib-number").text.gsub("total","").to_i
40-
end
41-
end
42-
43-
def open_url(url)
44-
Nokogiri::HTML(open(url))
45-
end
4622
end

app/models/stat.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Stat < ActiveRecord::Base
2+
validates :name, presence: true
3+
validates :commits, :numericality => { :greater_than => 0}, presence: true
4+
end
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,16 @@
7373
<h3 id="leaderboard">Leaderboard</h3>
7474
<table class="table">
7575
<tr>
76-
<td>Place</td>
7776
<td>Name</td>
77+
<td>Commits</td>
7878
</tr>
79-
<tr>
80-
<% n = 0 %>
81-
<% @group.each do |css| %>
82-
<td><%= n = n + 1 %></td>
83-
<td><%= css.join("- ") %> commits</td>
84-
</tr>
79+
<% @stats.each do |stat| %>
80+
<tr>
81+
<td><%= stat.name %></td>
82+
<td><%= stat.commits %></td>
83+
</tr>
8584
<% end %>
86-
<table>
85+
<table>
8786
</div>
8887
</div>
8988
</div>

config/routes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Rails.application.routes.draw do
2-
root "welcome#index"
2+
root "stats#index"
33
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class CreateStats < ActiveRecord::Migration
2+
def change
3+
create_table :stats do |t|
4+
t.string :name
5+
t.integer :commits
6+
7+
t.timestamps null: false
8+
end
9+
end
10+
end

db/schema.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,16 @@
1111
#
1212
# It's strongly recommended that you check this file into your version control system.
1313

14-
ActiveRecord::Schema.define(version: 0) do
14+
ActiveRecord::Schema.define(version: 20151007021403) do
1515

1616
# These are extensions that must be enabled in order to support this database
1717
enable_extension "plpgsql"
1818

19+
create_table "stats", force: :cascade do |t|
20+
t.string "name"
21+
t.integer "commits"
22+
t.datetime "created_at", null: false
23+
t.datetime "updated_at", null: false
24+
end
25+
1926
end

0 commit comments

Comments
 (0)