Skip to content
Browse files

populate more user details

grab gender, weight, height, etc.
  • Loading branch information...
1 parent 6777fa4 commit 36c5c56c83a8511d9c2f4665a629c38363556456 @mikepmunroe committed
View
13 app/models/athlete.rb
@@ -18,13 +18,24 @@ def self.populate_initial_data
end
end
- def self.populate_name
+ def self.populate_details
athletes = Athlete.all
athletes.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 = Array.new
+ details.xpath('//dd//text()').each do |attribute|
+ attributes << attribute.text
+ end
+ athlete.region = attributes[0]
+ athlete.team = attributes[1]
+ athlete.gender = attributes[3]
+ athlete.age = attributes[4]
+ athlete.height = attributes[5]
+ athlete.weight = attributes[6]
athlete.save
end
end
View
10 db/migrate/20130314005944_add_fields_to_athlete.rb
@@ -0,0 +1,10 @@
+class AddFieldsToAthlete < ActiveRecord::Migration
+ def change
+ add_column :athletes, :region, :string
+ add_column :athletes, :team, :string
+ add_column :athletes, :gender, :string
+ add_column :athletes, :age, :int
+ add_column :athletes, :height, :string
+ add_column :athletes, :weight, :int
+ end
+end
View
9 db/migrate/20130314010816_change_weight_in_athlete.rb
@@ -0,0 +1,9 @@
+class ChangeWeightInAthlete < ActiveRecord::Migration
+ def up
+ change_column :athletes, :weight, :string
+ end
+
+ def down
+ change_column :athletes, :weight, :int
+ end
+end
View
8 db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20130306003348) do
+ActiveRecord::Schema.define(:version => 20130314010816) do
create_table "athletes", :force => true do |t|
t.string "url"
@@ -24,6 +24,12 @@
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "affiliate"
+ t.string "region"
+ t.string "team"
+ t.string "gender"
+ t.integer "age"
+ t.string "height"
+ t.string "weight"
end
end

0 comments on commit 36c5c56

Please sign in to comment.
Something went wrong with that request. Please try again.