Skip to content

Commit

Permalink
Presidents now contain their country
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Vartanov committed Jan 8, 2010
1 parent 5d517e2 commit 8ab1143
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 3 deletions.
Binary file modified presidents/db/development.sqlite3
Binary file not shown.
@@ -0,0 +1,9 @@
class AddCountryToPresidents < ActiveRecord::Migration
def self.up
add_column :presidents, :country, :string
end

def self.down
remove_column :presidents, :country
end
end
3 changes: 2 additions & 1 deletion presidents/db/schema.rb
Expand Up @@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20091009101447) do
ActiveRecord::Schema.define(:version => 20100108065831) do

create_table "presidents", :force => true do |t|
t.string "first_name"
Expand All @@ -22,6 +22,7 @@
t.integer "term_ended_at"
t.datetime "created_at"
t.datetime "updated_at"
t.string "country"
end

end
2 changes: 2 additions & 0 deletions presidents/db/seeds.rb
Expand Up @@ -5,3 +5,5 @@
#
# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
# Major.create(:name => 'Daley', :city => cities.first)

require File.join(File.dirname(__FILE__), 'seeds', 'presidents')
Expand Up @@ -9,13 +9,13 @@ def attributes_from_match_data(attributes_names, match_data)

President.delete_all

File.open(File.join(File.dirname(__FILE__), 'presidents.txt')) do |file|
File.open(File.join(File.dirname(__FILE__), 'us-presidents.txt')) do |file|
while (line = file.gets)
match_data = line.match /(\d{1,2}). (\w*).*\s(\w*) \((\d{4})-(\d{4}|\s)\)\s*(.*)\s*(\d{4})-(\d{4}|\s)/

attributes_names = %w(order first_name last_name born_at died_at party term_started_at term_ended_at)
president_attributes = attributes_from_match_data(attributes_names, match_data)

President.create!(president_attributes)
President.create!(president_attributes.merge(:country => 'USA'))
end
end
File renamed without changes.

0 comments on commit 8ab1143

Please sign in to comment.