Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Just some minor changes. Totally untested. #3

Merged
merged 5 commits into from

2 participants

@davekaro

Added a link to the actual crossfit games profile page.
Tweaked a few of the xpath iterations to use Ruby #collect method instead of #each and shoving into array. #collect and #map are synonyms. My general preference is when you are just grabbing one attribute from the items in the collection, I think of that as "collect," meaning... go and collect all these attributes. I would use map when I wan to more or less transform a collection into another collection. I think of it like go and map this collection to something else. But like I said, they both do the same thing.

.collect(&:text) is just shorthand for .collect { |score| score.text }

@mikepmunroe mikepmunroe merged commit 9ef3225 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 18, 2013
  1. remove rails scaffold crap

    Dave Kroondyk authored
  2. link to games profile page

    Dave Kroondyk authored
  3. better link, no double slash

    Dave Kroondyk authored
  4. move todos to Github Issues

    Dave Kroondyk authored
This page is out of date. Refresh to see the latest.
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,21 +18,17 @@ 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
@@ -40,21 +36,17 @@ def self.populate_details
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>
+
Something went wrong with that request. Please try again.