Permalink
Browse files

Merge pull request #3 from davekaro/master

Just some minor changes. Totally untested.
  • Loading branch information...
2 parents ba5ae5f + b441ca2 commit 9ef3225ddf15b23f54d676ba2d91532e9e36f9d0 @mikepmunroe committed Mar 19, 2013
Showing with 12 additions and 42 deletions.
  1. +0 −10 README.md
  2. +1 −15 app/controllers/athletes_controller.rb
  3. +8 −15 app/models/athlete.rb
  4. +3 −2 app/views/athletes/index.html.erb
View
10 README.md
@@ -4,13 +4,3 @@ The [Crossfit Games](http://http://games.crossfit.com/) site has its [own leader
I get crushed at [Crossfit Wicked](http://www.crossfitwicked.com/) and some friends at work get crushed at [Crossfit Southie](http://crossfitsouthie.com/), so those are the only affiliates in the mix for now.
-TODO:
-- [ ] fix #2
-- [ ] create a specific view for Wicked and Southie affiliates
-- [ ] break out tables based off of gender and Games age groupings
-- [ ] spice up the design a bit instead of lame bootstrap
-
-Possible additions:
-- [ ] pull down scores for some other affiliates?
-- [ ] pull down scores from 2012?
-- [ ] create some more cooler views with some of the scoring data, maybe with some comparisons of 2012 vs. 2013 scores?
View
16 app/controllers/athletes_controller.rb
@@ -1,24 +1,10 @@
class AthletesController < ApplicationController
- # GET /athletes
- # GET /athletes.json
def index
- # @athletes = Athlete.all
@athletes = Athlete.order("total asc")
-
- respond_to do |format|
- format.html # index.html.erb
- format.json { render json: @athletes }
- end
end
- # GET /athletes/1
- # GET /athletes/1.json
def show
@athlete = Athlete.find(params[:id])
-
- respond_to do |format|
- format.html # show.html.erb
- format.json { render json: @athlete }
- end
end
end
+
View
23 app/models/athlete.rb
@@ -18,43 +18,35 @@ def self.populate_initial_data
end
def self.populate_details
- athletes = Athlete.all
- athletes.each do |athlete|
+ Athlete.all.each do |athlete|
details = Nokogiri::HTML(open("http://games.crossfit.com" + athlete.url))
name = details.at_css(".page-title").text
puts name
athlete.name = name.gsub(/^[^:]+:\s*/, "")
puts athlete.name
- attributes = []
- details.xpath('//dd//text()').each do |attribute|
- attributes << attribute.text
- end
+ attributes = details.xpath('//dd//text()').collect(&:text)
athlete.region = attributes[0]
- athlete.team = attributes[1]
+ athlete.team = attributes[1]
athlete.gender = attributes[3]
- athlete.age = attributes[4]
+ athlete.age = attributes[4]
athlete.height = attributes[5]
athlete.weight = attributes[6]
athlete.save
end
end
def self.populate_scores
- athletes = Athlete.all
- athletes.each do |athlete|
+ Athlete.all.each do |athlete|
details = Nokogiri::HTML(open("http://games.crossfit.com" + athlete.url))
leaderboard_src = details.xpath('//iframe[@id="cf_leaderboard"]/@src').text()
leaderboard = Nokogiri::HTML(open(leaderboard_src))
- scores = []
- values = []
- leaderboard.xpath('//table/tbody/tr[@class="highlight"]/td/span[@class="display"]/text()').each do |score|
- scores << score.text
- end
+ scores = leaderboard.xpath('//table/tbody/tr[@class="highlight"]/td/span[@class="display"]/text()').collect(&:text)
athlete.w1 = scores[0]
athlete.w2 = scores[1]
athlete.w3 = scores[2]
athlete.w4 = scores[3]
athlete.w5 = scores[4]
+ values = []
scores.each do |value|
if (match = value.scan(/\A\d*/))
values << match[0].to_i
@@ -65,3 +57,4 @@ def self.populate_scores
end
end
end
+
View
5 app/views/athletes/index.html.erb
@@ -18,7 +18,7 @@
<% @athletes.each do |athlete| %>
<tr>
<td><%= athlete.name %></td>
- <td><%= athlete.url %></td>
+ <td><%= line_to athlete.url, "http://games.crossfit.com#{athlete.url}" %></td>
<td><%= athlete.affiliate %></td>
<td><%= athlete.age %></td>
<td><%= athlete.w1 %></td>
@@ -30,4 +30,5 @@
</tr>
<% end %>
</tbody>
-</table>
+</table>
+

0 comments on commit 9ef3225

Please sign in to comment.