Class: GreatSchools::School

Inherits:
Model
  • Object
show all
Defined in:
lib/great_schools/school.rb

Overview

GreatSchools School

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Model

#initialize

Constructor Details

This class inherits a constructor from GreatSchools::Model

Instance Attribute Details

#addressObject

Returns the value of attribute address.



5
6
7
# File 'lib/great_schools/school.rb', line 5

def address
  @address
end

#cityObject

Returns the value of attribute city.



5
6
7
# File 'lib/great_schools/school.rb', line 5

def city
  @city
end

#districtObject

Returns the value of attribute district.



4
5
6
# File 'lib/great_schools/school.rb', line 4

def district
  @district
end

#district_idObject

Returns the value of attribute district_id.



4
5
6
# File 'lib/great_schools/school.rb', line 4

def district_id
  @district_id
end

#district_nces_idObject

Returns the value of attribute district_nces_id.



4
5
6
# File 'lib/great_schools/school.rb', line 4

def district_nces_id
  @district_nces_id
end

#enrollmentObject

Returns the value of attribute enrollment.



4
5
6
# File 'lib/great_schools/school.rb', line 4

def enrollment
  @enrollment
end

#faxObject

Returns the value of attribute fax.



5
6
7
# File 'lib/great_schools/school.rb', line 5

def fax
  @fax
end

#grade_rangeObject

Returns the value of attribute grade_range.



4
5
6
# File 'lib/great_schools/school.rb', line 4

def grade_range
  @grade_range
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/great_schools/school.rb', line 4

def id
  @id
end

#latitudeObject

Returns the value of attribute latitude.



5
6
7
# File 'lib/great_schools/school.rb', line 5

def latitude
  @latitude
end

#longitudeObject

Returns the value of attribute longitude.



5
6
7
# File 'lib/great_schools/school.rb', line 5

def longitude
  @longitude
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/great_schools/school.rb', line 4

def name
  @name
end

#nces_idObject

Returns the value of attribute nces_id.



4
5
6
# File 'lib/great_schools/school.rb', line 4

def nces_id
  @nces_id
end

Returns the value of attribute overview_link.



6
7
8
# File 'lib/great_schools/school.rb', line 6

def overview_link
  @overview_link
end

#parent_ratingObject

Returns the value of attribute parent_rating.



6
7
8
# File 'lib/great_schools/school.rb', line 6

def parent_rating
  @parent_rating
end

#parent_reviewsObject

Returns the value of attribute parent_reviews.



6
7
8
# File 'lib/great_schools/school.rb', line 6

def parent_reviews
  @parent_reviews
end

#phoneObject

Returns the value of attribute phone.



5
6
7
# File 'lib/great_schools/school.rb', line 5

def phone
  @phone
end

Returns the value of attribute ratings_link.



6
7
8
# File 'lib/great_schools/school.rb', line 6

def ratings_link
  @ratings_link
end

Returns the value of attribute reviews_link.



6
7
8
# File 'lib/great_schools/school.rb', line 6

def reviews_link
  @reviews_link
end

#stateObject

Returns the value of attribute state.



5
6
7
# File 'lib/great_schools/school.rb', line 5

def state
  @state
end

#typeObject

Returns the value of attribute type.



4
5
6
# File 'lib/great_schools/school.rb', line 4

def type
  @type
end

#websiteObject

Returns the value of attribute website.



5
6
7
# File 'lib/great_schools/school.rb', line 5

def website
  @website
end

Class Method Details

.browse(state, city, options = {}) ⇒ Object

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 ++



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/great_schools/school.rb', line 37

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 = {}) ⇒ Object

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 ++



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/great_schools/school.rb', line 81

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) ⇒ Object

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+
    


105
106
107
108
109
# File 'lib/great_schools/school.rb', line 105

def profile(state, id)
  response = GreatSchools::API.get("schools/#{state.upcase}/#{id}")

  new(response)
end

.search(state, query, options = {}) ⇒ Object

Returns a list of schools based on a search string.

Attributes

  • state - Two letter state abbreviation

  • query - Search query string

Options

  • :level - Level of school you wish to appear in the list:

    'elementary-schools', 'middle-schools', or 'high-schools'
    
  • :sort - This call by default sorts the results by relevance. You

    can sort the results alphabetically by using 'alpha'.
    
  • :limit - Maximum number of schools to return. This defaults to

    200 and must be at least 1.
    

– TODO: handle validations ++



129
130
131
132
133
134
135
136
137
138
# File 'lib/great_schools/school.rb', line 129

def search(state, query, options = {})
  options[:levelCode] = options.delete(:level)
  options[:q]         = query
  options[:state]     = state
  options.slice!(:state, :q, :levelCode, :sort, :limit)

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

  Array.wrap(response).map { |school| new(school) }
end

Instance Method Details

#censusObject

Returns census and profile data for the school.



142
143
144
# File 'lib/great_schools/school.rb', line 142

def census
  GreatSchools::Census.for_school(state, id)
end

#reviews(options = {}) ⇒ Object

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

Options

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



168
169
170
# File 'lib/great_schools/school.rb', line 168

def reviews(options = {})
  GreatSchools::Review.for_school(state, id, options.slice(:limit))
end

#scoreObject

Returns test and rank data for the school.



173
174
175
# File 'lib/great_schools/school.rb', line 173

def score
  GreatSchools::Score.for_school(state, id)
end