class GreatSchools::School

GreatSchools School

Attributes

address[RW]
city[RW]
district[RW]
district_id[RW]
district_nces_id[RW]
enrollment[RW]
fax[RW]
grade_range[RW]
gs_id=[RW]
gs_rating=[RW]
id[RW]
lat=[RW]
latitude[RW]
lon=[RW]
longitude[RW]
name[RW]
nces_id[RW]
parent_rating[RW]
parent_reviews[RW]
phone[RW]
rating[RW]
state[RW]
type[RW]
website[RW]

Public Class Methods

browse(state, city, options = {}) click to toggle source

Returns a list of schools in a city.

Attributes

  • state - Two letter state abbreviation

  • city - Name of city

Options

  • :school_types - Type of school(s) you wish to appear in the list:

    'public', 'charter', and/or 'private'
  • :level - Level of school you wish to appear in the list:

    'elementary-schools', 'middle-schools', or 'high-schools'
  • :sort - How to sort the results, either by name (ascending),

    by GreatSchools rating (descending), or by overall
    parent rating (descending). The default sort is name
    (ascending). When sorted by rating, schools without
    a rating will appear last. Options: 'name',
    'gs_rating', or 'parent_rating'
  • :limit - Maximum number of schools to return. This defaults

    to 200. To get all results, use -1.

– TODO: handle validations ++

# File lib/great_schools/school.rb, line 38
def browse(state, city, options = {})
  school_types  = Array.wrap(options.delete(:school_types)).join('-')
  level         = options.delete(:level)

  url = "schools/#{state.upcase}/#{parameterize(city)}"
  url << "/#{school_types}" if school_types.present?
  url << "/#{level}"        if level.present?

  response = GreatSchools::API.get(url, options.slice(:sort, :limit))

  Array.wrap(response).map { |school| new(school) }
end
nearby(state, options = {}) click to toggle source

Returns a list of schools closest to the center of a city, ZIP Code or address.

Attributes

  • state - Two letter state abbreviation

Options

  • :zip_code - 5 digit zip code

  • :city - Name of city

  • :address - Address of location

  • :latitude - Latitude of location

  • :longitude - Longitude of location

  • :school_types - Type of school(s) you wish to appear in the list:

    'public', 'charter', and/or 'private'
  • :level - Level of school you wish to appear in the list:

    'elementary-schools', 'middle-schools', or 'high-schools'
  • :minimum_schools - Minimum number of schools to return. When provided,

    if the initial query field yields fewer schools than
    this value, the radius will be increased in 5 mile
    increments to a maximum of 50 miles or until the
    result set has enough schools to meet this value.
    Maximum value is 200. This value must be less than
    the limit or else it is ignored.
  • :radius - Miles radius to confine search to. This default to 5,

    with a maximum of 50
    
  • :limit - Maximum number of schools to return. This defaults to 200.

– TODO: handle validations ++

# File lib/great_schools/school.rb, line 82
def nearby(state, options = {})
  options[:lat]             = options.delete(:latitude)
  options[:levelCode]       = options.delete(:level)
  options[:lon]             = options.delete(:longitude)
  options[:minimumSchools]  = options.delete(:minimum_schools)
  options[:schoolType]      = options.delete(:school_types).try(:join, '-')
  options[:state]           = state
  options[:zip]             = options.delete(:zip_code)

  options.slice!(:address, :city, :lat, :levelCode, :limit, :lon, :minimumSchools, :radius, :schoolType, :state, :zip)

  response = GreatSchools::API.get('schools/nearby', options)

  Array.wrap(response).map { |school| new(school) }
end
profile(state, id) click to toggle source

Returns profile data for a specific school.

Attributes

  • state - Two letter state abbreviation

  • id - Numeric id of a school. This GreatSchools ID is included in

    other listing requests like +GreatSchools::School#browse+
    and +GreatSchools::School#nearby+
# File lib/great_schools/school.rb, line 106
def profile(state, id)
  response = GreatSchools::API.get("schools/#{state.upcase}/#{id}")

  new(response)
end

Public Instance Methods

census() click to toggle source

Returns census and profile data for the school.

# File lib/great_schools/school.rb, line 143
def census
  GreatSchools::Census.for_school(state, id)
end
parent_reviews=(params) click to toggle source

Set an array of GreatSchools::Review.

Attributes

  • params - a Hash or Array of GreatSchools::Review attributes.

# File lib/great_schools/school.rb, line 152
def parent_reviews=(params)
  @parent_reviews = []

  params = params['review'] if params.is_a?(Hash) && params.key?('review')

  Array.wrap(params).each do |hash|
    @parent_reviews << GreatSchools::Review.new(hash)
  end

  @parent_reviews
end
reviews(options = {}) click to toggle source

Returns a list of the most recent reviews for the school.

Options

  • :limit - Maximum number of reviews to return. This defaults to 5.

# File lib/great_schools/school.rb, line 169
def reviews(options = {})
  GreatSchools::Review.for_school(state, id, options.slice(:limit))
end
score() click to toggle source

Returns test and rank data for the school.

# File lib/great_schools/school.rb, line 174
def score
  GreatSchools::Score.for_school(state, id)
end