donors_choose 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in donors_choose.gemspec
4
+ gemspec
data/README.textile ADDED
@@ -0,0 +1,51 @@
1
+ h1. donors_choose
2
+
3
+ This library sprung from the 2011 Hacking Education contest for DonorsChoose.org. (http://www.donorschoose.org/hacking-education)
4
+
5
+ The DonorsChoose::Data module match up the normalized data provided by DonorsChoose.org to classes that inherit from ActiveRecord::Base.
6
+
7
+ *This gem assumes you have loaded the DonorsChoose.org datasets into a PostgreSQL database.*
8
+
9
+ h2. Usage
10
+
11
+ <code>
12
+ project = DonorsChoose::Data::Project.first
13
+ project.donations
14
+ school = DonorsChoose::Data::School.last
15
+ school.teachers
16
+ </code>
17
+
18
+
19
+ h3. Rails
20
+
21
+ If you'd like to use it in Rails, just add the following to your Gemfile:
22
+
23
+ <code>
24
+ gem 'donors_choose'
25
+ </code>
26
+
27
+ h3. Stand alone
28
+
29
+ If you'd like to use it stand alone, do the following:
30
+
31
+ Create a database.yml, very similar to what you'd have in Rails:
32
+
33
+ bq. adapter: postgresql
34
+ host: localhost
35
+ username: postgres
36
+ password: password
37
+ port: 5432
38
+ database: donors_choose_data
39
+ schema_search_path: public
40
+
41
+ Then, drop into irb, require the gem, and establish the db connection
42
+
43
+ <code>
44
+ terminal$ irb
45
+ irb(main):001:0> require 'rubygems'
46
+ irb(main):001:0> require 'donors_choose'
47
+ irb(main):001:0> DonorsChoose::Data.connect(YAML.load(File.read('database.yml')))
48
+ irb(main):001:0> DonorsChoose::Data::Project.first
49
+ </code>
50
+
51
+
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ # Bundler tasks
2
+ require 'bundler'
3
+ Bundler::GemHelper.install_tasks
4
+
5
+ # Test tasks
6
+ require 'rake'
7
+ require 'rake/testtask'
8
+
9
+ desc "Run basic tests"
10
+ Rake::TestTask.new("test_units") { |t|
11
+ t.pattern = 'test/*/*/*_test.rb'
12
+ t.verbose = true
13
+ t.warning = true
14
+ }
15
+
16
+ task :default => [:test_units]
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "donors_choose/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "donors_choose"
7
+ s.version = DonorsChoose::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Mark McSpadden"]
10
+ s.email = [""]
11
+ s.homepage = ""
12
+ s.summary = %q{Libaries to assist with mining and utilizing donorschoose.org}
13
+ s.description = %q{}
14
+
15
+ s.rubyforge_project = "donors_choose"
16
+
17
+ s.add_dependency 'activerecord', '> 3.0'
18
+ s.add_dependency 'pg'
19
+
20
+ s.files = `git ls-files`.split("\n")
21
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
23
+ s.require_paths = ["lib"]
24
+ end
@@ -0,0 +1,5 @@
1
+ module DonorsChoose
2
+
3
+ end
4
+
5
+ require File.expand_path(File.dirname(__FILE__) + "/donors_choose/data")
@@ -0,0 +1,18 @@
1
+ require 'active_record'
2
+ require 'pg'
3
+
4
+ module DonorsChoose
5
+ module Data
6
+
7
+ # Use this if you're going standalone (aka sans Rails)
8
+ def self.connect(postgres_config = {})
9
+ # Connect with db
10
+ ActiveRecord::Base.establish_connection(postgres_config)
11
+ end
12
+
13
+ Dir.glob("#{File.dirname __FILE__}/data/*.rb").each do |f|
14
+ require f
15
+ end
16
+ end
17
+ end
18
+
@@ -0,0 +1,10 @@
1
+ module DonorsChoose
2
+ module Data
3
+ class Account < ActiveRecord::Base
4
+ set_table_name :normalized_account
5
+ set_primary_key :_acctid
6
+
7
+ belongs_to :city, :foreign_key => :cityid
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ module DonorsChoose
2
+ module Data
3
+ class City < ActiveRecord::Base
4
+ set_table_name :normalized_city
5
+
6
+ has_many :accounts, :foreign_key => :cityid
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ module DonorsChoose
2
+ module Data
3
+ class Donation < ActiveRecord::Base
4
+ set_table_name :normalized_donation
5
+ set_primary_key :_donationid
6
+
7
+ belongs_to :project, :foreign_key => :_projectid
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module DonorsChoose
2
+ module Data
3
+ class Essay < ActiveRecord::Base
4
+ set_table_name :normalized_essay
5
+ set_primary_key :_projectid
6
+
7
+ belongs_to :project, :foreign_key => :_projectid
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,8 @@
1
+ module DonorsChoose
2
+ module Data
3
+ class Giftcard < ActiveRecord::Base
4
+ set_table_name :normalized_giftcard
5
+ set_primary_key :_giftcardid
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,16 @@
1
+ module DonorsChoose
2
+ module Data
3
+ class Project < ActiveRecord::Base
4
+ set_table_name :normalized_project
5
+ set_primary_key :_projectid
6
+
7
+ belongs_to :school, :foreign_key => :_schoolid
8
+ belongs_to :teacher, :foreign_key => :_teacher_acctid
9
+
10
+ has_one :essay, :foreign_key => :_projectid
11
+
12
+ has_many :donations, :foreign_key => :_projectid
13
+ has_many :resources, :foreign_key => :_projectid
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,10 @@
1
+ module DonorsChoose
2
+ module Data
3
+ class Resource < ActiveRecord::Base
4
+ set_table_name :normalized_resource
5
+ set_primary_key :_resourceid
6
+
7
+ belongs_to :project, :foreign_key => :_projectid
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ module DonorsChoose
2
+ module Data
3
+ class School < ActiveRecord::Base
4
+ set_table_name :normalized_school
5
+ set_primary_key :_schoolid
6
+
7
+ has_many :projects, :foreign_key => :_schoolid
8
+ has_many :teachers, :through => :projects
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module DonorsChoose
2
+ module Data
3
+ class Teacher < ActiveRecord::Base
4
+ set_table_name :normalized_teacher
5
+ set_primary_key :_teacher_acctid
6
+
7
+ has_many :projects, :foreign_key => :_teacher_acctid
8
+ has_many :schools, :through => :projects
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module DonorsChoose
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,17 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ class AccountTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @account = DonorsChoose::Data::Account.order(:_acctid).first
7
+ end
8
+
9
+ def test_account_setup
10
+ assert_equal "00008481214e948f070337066f875fb2", @account._acctid
11
+ end
12
+
13
+ def test_city_setup
14
+ assert_equal 4474, @account.city.id
15
+ end
16
+
17
+ end
@@ -0,0 +1,17 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ class CityTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @city = DonorsChoose::Data::City.first
7
+ end
8
+
9
+ def test_city_setup
10
+ assert_equal 1, @city.id
11
+ end
12
+
13
+ def test_accounts_setup
14
+ assert_equal "c4127fe826abef12174ca4d0e7288f88", @city.accounts.first._acctid
15
+ end
16
+
17
+ end
@@ -0,0 +1,16 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ class DonationTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @donation = DonorsChoose::Data::Donation.order(:_donationid).first
7
+ end
8
+
9
+ def test_donation_setup
10
+ assert_equal "0000023f507999464aa2b78875b7e5d6", @donation._donationid
11
+ end
12
+
13
+ def test_project_setup
14
+ assert_equal "69bf3a609bb4673818e0eebd004ea504", @donation.project._projectid
15
+ end
16
+ end
@@ -0,0 +1,17 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ class EssayTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @essay = DonorsChoose::Data::Essay.order(:_projectid).first
7
+ end
8
+
9
+ def test_essay_setup
10
+ assert_equal "0000023f507999464aa2b78875b7e5d6", @essay._projectid
11
+ end
12
+
13
+ def test_project_setup
14
+ assert_equal "0000023f507999464aa2b78875b7e5d6", @essay.project._projectid
15
+ end
16
+
17
+ end
@@ -0,0 +1,13 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ class GiftcardTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @giftcard = DonorsChoose::Data::Giftcard.order(:_giftcardid).first
7
+ end
8
+
9
+ def test_giftcard_setup
10
+ assert_equal "000238b44c187c254752736e53ee46f2", @giftcard._giftcardid
11
+ end
12
+
13
+ end
@@ -0,0 +1,33 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ class ProjectTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @project = DonorsChoose::Data::Project.order(:_projectid).first
7
+ end
8
+
9
+ def test_project_setup
10
+ assert_equal "0000023f507999464aa2b78875b7e5d6", @project._projectid
11
+ end
12
+
13
+ def test_donation_setup
14
+ assert_equal "ee519de971e6ec8961f5efa06c6ed191", @project.donations.first._donationid
15
+ end
16
+
17
+ def test_essay_setup
18
+ assert_equal "0000023f507999464aa2b78875b7e5d6", @project.essay._projectid
19
+ end
20
+
21
+ def test_teacher_setup
22
+ assert_equal "5ac258059d9c4fc4db5c1a92b7204db0", @project.teacher._teacher_acctid
23
+ end
24
+
25
+ def test_resources_setup
26
+ assert_equal "179328a86f77fd5516d122f371c41d32", @project.resources.first._resourceid
27
+ end
28
+
29
+ def test_school_setup
30
+ assert_equal "c8eafeea02033a1cacd629b410668d55", @project.school._schoolid
31
+ end
32
+
33
+ end
@@ -0,0 +1,17 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ class ResourceTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @resource = DonorsChoose::Data::Resource.order(:_resourceid).first
7
+ end
8
+
9
+ def test_resource_setup
10
+ assert_equal "00000170fe6288e0bc4d136e7d9b5ff2", @resource._resourceid
11
+ end
12
+
13
+ def test_project_setup
14
+ assert_equal "401699836249c08c7a686b33e243b826", @resource.project._projectid
15
+ end
16
+
17
+ end
@@ -0,0 +1,16 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ class SchoolTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @school = DonorsChoose::Data::School.order(:_schoolid).first
7
+ end
8
+
9
+ def test_school_setup
10
+ assert_equal "00064eac8b3d1f6dea8a07559922ed58", @school._schoolid
11
+ end
12
+
13
+ def test_project_setup
14
+ assert_equal "2934f1c8ae5069a41fe601dcf57601be", @school.projects.first._projectid
15
+ end
16
+ end
@@ -0,0 +1,21 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ class TeacherTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @teacher = DonorsChoose::Data::Teacher.order(:_teacher_acctid).first
7
+ end
8
+
9
+ def test_teacher_setup
10
+ assert_equal "0000fc70ad0a307d08f88a484dd99cb4", @teacher._teacher_acctid
11
+ end
12
+
13
+ def test_projects_setup
14
+ assert_equal "dde9ff3a749c46a5d6d6be4f37b0dba6", @teacher.projects.first._projectid
15
+ end
16
+
17
+ def test_schools_setup
18
+ assert_equal "3a379fd45cb12c92c3c4283e97421111", @teacher.schools.first._schoolid
19
+ end
20
+
21
+ end
@@ -0,0 +1,15 @@
1
+ require 'test/unit'
2
+
3
+ require 'rubygems'
4
+
5
+ require File.expand_path(File.dirname(__FILE__) + "/../lib/donors_choose/data")
6
+
7
+ postgres_config = { :adapter => "postgresql",
8
+ :host => "localhost",
9
+ :username => "postgres",
10
+ :password => "password",
11
+ :port => 5432,
12
+ :database => "donors_choose_data",
13
+ :schema_search_path => "public" }
14
+
15
+ DonorsChoose::Data.connect postgres_config
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: donors_choose
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Mark McSpadden
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-05-26 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: activerecord
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">"
28
+ - !ruby/object:Gem::Version
29
+ hash: 7
30
+ segments:
31
+ - 3
32
+ - 0
33
+ version: "3.0"
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: pg
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ type: :runtime
49
+ version_requirements: *id002
50
+ description: ""
51
+ email:
52
+ - ""
53
+ executables: []
54
+
55
+ extensions: []
56
+
57
+ extra_rdoc_files: []
58
+
59
+ files:
60
+ - Gemfile
61
+ - README.textile
62
+ - Rakefile
63
+ - donors_choose.gemspec
64
+ - lib/donors_choose.rb
65
+ - lib/donors_choose/data.rb
66
+ - lib/donors_choose/data/account.rb
67
+ - lib/donors_choose/data/city.rb
68
+ - lib/donors_choose/data/donation.rb
69
+ - lib/donors_choose/data/essay.rb
70
+ - lib/donors_choose/data/giftcard.rb
71
+ - lib/donors_choose/data/project.rb
72
+ - lib/donors_choose/data/resource.rb
73
+ - lib/donors_choose/data/school.rb
74
+ - lib/donors_choose/data/teacher.rb
75
+ - lib/donors_choose/version.rb
76
+ - test/donors_choose/data/account_test.rb
77
+ - test/donors_choose/data/city_test.rb
78
+ - test/donors_choose/data/donation_test.rb
79
+ - test/donors_choose/data/essay_test.rb
80
+ - test/donors_choose/data/giftcard_test.rb
81
+ - test/donors_choose/data/project_test.rb
82
+ - test/donors_choose/data/resource_test.rb
83
+ - test/donors_choose/data/school_test.rb
84
+ - test/donors_choose/data/teacher_test.rb
85
+ - test/test_helper.rb
86
+ has_rdoc: true
87
+ homepage: ""
88
+ licenses: []
89
+
90
+ post_install_message:
91
+ rdoc_options: []
92
+
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ hash: 3
101
+ segments:
102
+ - 0
103
+ version: "0"
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ hash: 3
110
+ segments:
111
+ - 0
112
+ version: "0"
113
+ requirements: []
114
+
115
+ rubyforge_project: donors_choose
116
+ rubygems_version: 1.3.7
117
+ signing_key:
118
+ specification_version: 3
119
+ summary: Libaries to assist with mining and utilizing donorschoose.org
120
+ test_files:
121
+ - test/donors_choose/data/account_test.rb
122
+ - test/donors_choose/data/city_test.rb
123
+ - test/donors_choose/data/donation_test.rb
124
+ - test/donors_choose/data/essay_test.rb
125
+ - test/donors_choose/data/giftcard_test.rb
126
+ - test/donors_choose/data/project_test.rb
127
+ - test/donors_choose/data/resource_test.rb
128
+ - test/donors_choose/data/school_test.rb
129
+ - test/donors_choose/data/teacher_test.rb
130
+ - test/test_helper.rb