Skip to content

Instantly share code, notes, and snippets.

@Brandon-Lyons
Created October 3, 2014 21:08
Show Gist options
  • Select an option

  • Save Brandon-Lyons/d107cb80d1e0605929e1 to your computer and use it in GitHub Desktop.

Select an option

Save Brandon-Lyons/d107cb80d1e0605929e1 to your computer and use it in GitHub Desktop.
class College < ActiveRecord::Base
include IPEDValueConverters
has_many :college_coach_contacts
has_many :interested_athletes, :through => :preferred_colleges_join, :class_name => "Athlete", :source => :athlete, :uniq => true
has_many :preferred_colleges_join, :class_name => "PreferredCollege", :uniq => true
scope :active, -> { where active: true }
scope :inactive, -> { where active: false }
searchable do
text :name do
name_humanized
end
string :name_humanized
string :sport_or_departments, multiple: true do
college_coach_contacts.map { |c| c.sport_or_department unless c.sport_or_department.blank? }
end
text :cities do
college_coach_contacts.pluck(:city).join(" ") unless college_coach_contacts.blank?
end
string :city
string :state
string :zips, multiple: true do
college_coach_contacts.map { |c| c.zip[0..2] unless c.zip.blank? }
end
string :division
end
def city
college_coach_contacts.first.city
end
def iped_admission_test_scores
admission_test_scores read_attribute(:iped_admission_test_scores)
end
def iped_other_test
other_test read_attribute(:iped_other_test)
end
def iped_toefl
toefl read_attribute(:iped_toefl)
end
def iped_fall_reporting_period_for_sat_act_test_scores
fall_reporting_period_for_sat_act_test_scores read_attribute(:iped_fall_reporting_period_for_sat_act_test_scores)
end
def iped_full_time_first_time_degree_certificate_seeking_students_required_to_live_on_campus
full_time_first_time_degree_certificate_seeking_students_required_to_live_on_campus read_attribute(:iped_full_time_first_time_degree_certificate_seeking_students_required_to_live_on_campus)
end
def iped_institution_provide_on_campus_housing
institution_provide_on_campus_housing read_attribute(:iped_institution_provide_on_campus_housing)
end
def iped_institution_provides_board_or_meal_plan
institution_provides_board_or_meal_plan read_attribute(:iped_institution_provides_board_or_meal_plan)
end
def iped_carnegie_classification_2010_graduate_instructional_program
carnegie_classification_2010_graduate_instructional_program read_attribute(:iped_carnegie_classification_2010_graduate_instructional_program)
end
def iped_carnegie_classification_2010_undergraduate_instructional_program
carnegie_classification_2010_undergraduate_instructional_program read_attribute(:iped_carnegie_classification_2010_undergraduate_instructional_program)
end
def iped_carnegie_classification_2010_basic
carnegie_classification_2010_basic read_attribute(:iped_carnegie_classification_2010_basic)
end
def iped_institutional_category
institutional_category read_attribute(:iped_institutional_category)
end
def iped_postsecondary_and_title_iv_institution_indicator
postsecondary_and_title_iv_institution_indicator read_attribute(:iped_postsecondary_and_title_iv_institution_indicator)
end
def iped_degree_of_urbanization
degree_of_urbanization read_attribute(:iped_degree_of_urbanization)
end
def iped_tribal_college
tribal_college read_attribute(:iped_tribal_college)
end
def iped_historically_black_college_or_university
historically_black_college_or_university read_attribute(:iped_historically_black_college_or_university)
end
def iped_control_of_institution
control_of_institution read_attribute(:iped_control_of_institution)
end
def iped_level_of_institution
level_of_institution read_attribute(:iped_level_of_institution)
end
def iped_geographic_region with_states = false
region_name = geographic_region_name read_attribute(:iped_geographic_region)
region_states = geographic_region_states read_attribute(:iped_geographic_region)
with_states ? "#{region_name} #{region_states}".squish : region_name
end
end
module IPEDValueConverters
extend ActiveSupport::Concern
def admission_test_scores iped_admission_test_scores
case iped_admission_test_scores
when -2
"Not applicable"
when -1
"Not reported"
when 1
"Required"
when 2
"Recommended"
when 3
"Neither required nor recommended"
when 4
"Do not know"
end
end
def other_test iped_other_test
case iped_other_test
when -2
"Not applicable"
when -1
"Not reported"
when 1
"Required"
when 2
"Recommended"
when 3
"Neither required nor recommended"
when 4
"Do not know"
end
end
def toefl iped_toefl
case iped_toefl
when -2
"Not applicable"
when -1
"Not reported"
when 1
"Required"
when 2
"Recommended"
when 3
"Neither required nor recommended"
when 4
"Do not know"
end
end
def fall_reporting_period_for_sat_act_test_scores iped_fall_reporting_period_for_sat_act_test_scores
case iped_fall_reporting_period_for_sat_act_test_scores
when -2
"Not applicable"
when -1
"Not reported"
when 1
"Fall 2011"
when 2
"Fall 2012"
when 3
"Test scores not required"
end
end
def full_time_first_time_degree_certificate_seeking_students_required_to_live_on_campus iped_full_time_first_time_degree_certificate_seeking_students_required_to_live_on_campus
case iped_full_time_first_time_degree_certificate_seeking_students_required_to_live_on_campus
when -2
"Not applicable"
when -1
"Not reported"
when 1
"Yes"
when 2
"No"
end
end
def institution_provide_on_campus_housing iped_institution_provide_on_campus_housing
case iped_institution_provide_on_campus_housing
when -2
"Not applicable"
when -1
"Not reported"
when 1
"Yes"
when 2
"No"
end
end
def institution_provides_board_or_meal_plan iped_institution_provides_board_or_meal_plan
case iped_institution_provides_board_or_meal_plan
when -2
"Not applicable"
when -1
"Not reported"
when 1
"Yes, number of meals in the maximum meal plan offered"
when 2
"Yes, number of meals per week can vary"
when 3
"No"
end
end
def carnegie_classification_2010_graduate_instructional_program iped_carnegie_classification_2010_graduate_instructional_program
case iped_carnegie_classification_2010_undergraduate_instructional_program
when -3
"Not applicable, not in Carnegie universe (not accredited or nondegree-granting)"
when -2
"Not applicable, special focus institution"
when -1
"Not applicable"
when 0
"Not classified"
when 1
"Single postbaccalaureate (education)"
when 2
"Single postbaccalaureate (business)"
when 3
"Single postbaccalaureate (other field)"
when 4
"Postbaccalaureate comprehensive"
when 5
"Postbaccalaureate, arts & sciences dominant"
when 6
"Postbaccalaureate with arts & sciences (education dominant)"
when 7
"Postbaccalaureate with arts & sciences (business dominant)"
when 8
"Postbaccalaureate with arts & sciences (other dominant fields)"
when 9
"Postbaccalaureate professional (education dominant)"
when 10
"Postbaccalaureate professional (business dominant)"
when 11
"Postbaccalaureate professional (other dominant fields)"
when 12
"Single doctoral (education)"
when 13
"Single doctoral (other field)"
when 14
"Comprehensive doctoral with medical/veterinary"
when 15
"Comprehensive doctoral (no medical/veterinary)"
when 16
"Doctoral, humanities/social sciences dominant"
when 17
"STEM dominant"
when 18
"Doctoral, professional dominant"
end
end
def carnegie_classification_2010_undergraduate_instructional_program iped_carnegie_classification_2010_undergraduate_instructional_program
case iped_carnegie_classification_2010_undergraduate_instructional_program
when -3
"Not applicable, not in Carnegie universe (not accredited or nondegree-granting)"
when -2
"Not applicable, special focus institution"
when -1
"Not applicable, graduate institution"
when 0
"Not classified"
when 1
"Associates"
when 2
"Associates Dominant"
when 3
"Arts & sciences focus, no graduate coexistence"
when 4
"Arts & sciences focus, some graduate coexistence"
when 5
"Arts & sciences focus, high graduate coexistence"
when 6
"Arts & sciences plus professions, no graduate coexistence"
when 7
"Arts & sciences plus professions, some graduate coexistence"
when 8
"Arts & sciences plus professions, high graduate coexistence"
when 9
"Balanced arts & sciences/professions, no graduate coexistence"
when 10
"Balanced arts & sciences/professions, some graduate coexistence"
when 11
"Balanced arts & sciences/professions, high graduate coexistence"
when 12
"Professions plus arts & sciences, no graduate coexistence"
when 13
"Professions plus arts & sciences, some graduate coexistence"
when 14
"Professions plus arts & sciences, high graduate coexistence"
when 15
"Professions focus, no graduate coexistence"
when 16
"Professions focus, some graduate coexistence"
when 17
"Professions focus, high graduate coexistence"
end
end
def carnegie_classification_2010_undergraduate_instructional_program iped_carnegie_classification_2010_undergraduate_instructional_program
case iped_iped_carnegie_classification_2010_undergraduate_instructional_program
when -3
"Not applicable, not in Carnegie universe (not accredited or nondegree-granting)"
when 0
"Not classified"
when 1
"Associate's--Public Rural-serving Small"
when 2
"Associate's--Public Rural-serving Medium"
when 3
"Associate's--Public Rural-serving Large"
when 4
"Associate's--Public Suburban-serving Single Campus"
when 5
"Associate's--Public Suburban-serving Multicampus"
when 6
"Associate's--Public Urban-serving Single Campus"
when 7
"Associate's--Public Urban-serving Multicampus"
when 8
"Associate's--Public Special Use"
when 9
"Associate's--Private Not-for-profit"
when 10
"Associate's--Private For-profit"
when 11
"Associate's--Public 2-year colleges under 4-year universities"
when 12
"Associate's--Public 4-year Primarily Associate's"
when 13
"Associate's--Private Not-for-profit 4-year Primarily Associate's"
when 14
"Associate's--Private For-profit 4-year Primarily Associate's"
when 15
"Research Universities (very high research activity)"
when 16
"Research Universities (high research activity)"
when 17
"Doctoral/Research Universities"
when 18
"Master's Colleges and Universities (larger programs)"
when 19
"Master's Colleges and Universities (medium programs)"
when 20
"Master's Colleges and Universities (smaller programs)"
when 21
"Baccalaureate Colleges--Arts & Sciences"
when 22
"Baccalaureate Colleges--Diverse Fields"
when 23
"Baccalaureate/Associate's Colleges"
when 24
"Theological seminaries, Bible colleges, and other faith-related institutions"
when 25
"Medical schools and medical centers"
when 26
"Other health professions schools"
when 27
"Schools of engineering"
when 28
"Other technology-related schools"
when 29
"Schools of business and management"
when 30
"Schools of art, music, and design"
when 31
"Schools of law"
when 32
"Other special-focus institutions"
when 33
"Tribal Colleges"
end
end
def carnegie_classification_2010_basic iped_carnegie_classification_2010_basic
case iped_carnegie_classification_2010_basic
when -3
"Not applicable, not in Carnegie universe (not accredited or nondegree-granting)"
when 0
"Not classified"
when 1
"Associate's--Public Rural-serving Small"
when 2
"Associate's--Public Rural-serving Medium"
when 3
"Associate's--Public Rural-serving Large"
when 4
"Associate's--Public Suburban-serving Single Campus"
when 5
"Associate's--Public Suburban-serving Multicampus"
when 6
"Associate's--Public Urban-serving Single Campus"
when 7
"Associate's--Public Urban-serving Multicampus"
when 8
"Associate's--Public Special Use"
when 9
"Associate's--Private Not-for-profit"
when 10
"Associate's--Private For-profit"
when 11
"Associate's--Public 2-year colleges under 4-year universities"
when 12
"Associate's--Public 4-year Primarily Associate's"
when 13
"Associate's--Private Not-for-profit 4-year Primarily Associate's"
when 14
"Associate's--Private For-profit 4-year Primarily Associate's"
when 15
"Research Universities (very high research activity)"
when 16
"Research Universities (high research activity)"
when 17
"Doctoral/Research Universities"
when 18
"Master's Colleges and Universities (larger programs)"
when 19
"Master's Colleges and Universities (medium programs)"
when 20
"Master's Colleges and Universities (smaller programs)"
when 21
"Baccalaureate Colleges--Arts & Sciences"
when 22
"Baccalaureate Colleges--Diverse Fields"
when 23
"Baccalaureate/Associate's Colleges"
when 24
"Theological seminaries, Bible colleges, and other faith-related institutions"
when 25
"Medical schools and medical centers"
when 26
"Other health professions schools"
when 27
"Schools of engineering"
when 28
"Other technology-related schools"
when 29
"Schools of business and management"
when 30
"Schools of art, music, and design"
when 31
"Schools of law"
when 32
"Other special-focus institutions"
when 33
"Tribal Colleges"
end
end
def institutional_category iped_institutional_category
case iped_institutional_category
when -1
"Not reported"
when -2
"Not applicable"
when 1
"Degree-granting, graduate with no undergraduate degrees"
when 2
"Degree-granting, primarily baccalaureate or above"
when 3
"Degree-granting, not primarily baccalaureate or above"
when 4
"Degree-granting, associate's and certificates"
when 5
"Nondegree-granting, above the baccalaureate"
when 6
"Nondegree-granting, sub-baccalaureate"
end
end
def postsecondary_and_title_iv_institution_indicator iped_postsecondary_and_title_iv_institution_indicator
case iped_postsecondary_and_title_iv_institution_indicator
when 1
"Title IV postsecondary institution"
when 2
"Non-Title IV postsecondary institution"
when 3
"Title IV NOT primarily postsecondary institution"
when 4
"Non-Title IV NOT primarily postsecondary institution"
when 5
"Title IV postsecondary institution that is NOT open to the public"
when 6
"Non-Title IV postsecondary institution that is NOT open to the public"
when 9
"institution inactive"
end
end
def degree_of_urbanization iped_degree_of_urbanization
case iped_degree_of_urbanization
when -3
"Not available"
when 11
"City: Large"
when 12
"City: Midsize"
when 13
"City: Small"
when 21
"Suburb: Large"
when 22
"Suburb: Midsize"
when 23
"Suburb: Small"
when 31
"Town: Fringe"
when 32
"Town: Distant"
when 33
"Town: Remote"
when 41
"Rural: Fringe"
when 42
"Rural: Distant"
when 43
"Rural: Remote"
end
end
def tribal_college iped_tribal_college
case iped_tribal_college
when 1
"Yes"
when 2
"No"
end
end
def historically_black_college_or_university iped_historically_black_college_or_university
case iped_historically_black_college_or_university
when 1
"Yes"
when 2
"No"
end
end
def degree_granting_status iped_degree_granting_status
case iped_degree_granting_status
when -3
"Not available"
when 1
"Degree-granting"
when 2
"Nondegree-granting, primarily postsecondary"
end
end
def control_of_institution iped_control_of_institution
case iped_control_of_institution
when -3
"Not available"
when 1
"Public"
when 2
"Private not-for-profit"
when 3
"Private for-profit"
end
end
def level_of_institution iped_level_of_institution
case iped_level_of_institution
when -3
"Not available"
when 1
"Four or more years"
when 2
"At least 2 but less than 4 years"
when 3
"Less than 2 years (below associate)"
end
end
def geographic_region_name iped_geographic_region_number
case iped_geographic_region_number
when -3
"Not available"
when 0
"US Service schools"
when 1
"New England"
when 2
"Mid East"
when 3
"Great Lakes"
when 4
"Plains"
when 5
"Southeast"
when 6
"Southwest"
when 7
"Rocky Mountains"
when 8
"Far West"
when 9
"Outlying areas"
end
end
def geographic_region_states iped_geographic_region_number
case iped_geographic_region_number
when 1
"CT ME MA NH RI VT"
when 2
"DE DC MD NJ NY PA"
when 3
"IL IN MI OH WI"
when 4
"IA KS MN MO NE ND SD"
when 5
"AL AR FL GA KY LA MS NC SC TN VA WV"
when 6
"AZ NM OK TX"
when 7
"CO ID MT UT WY"
when 8
"AK CA HI NV OR WA"
when 9
"AS FM GU MH MP PR PW VI"
else
""
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment