Class: GreatSchools::City
Overview
GreatSchools City
– TODO: add method to grab nearby schools using GreatSchools::School#nearby with the city
and state
options. ++
Instance Attribute Summary collapse
-
#charter_schools ⇒ Object
Returns the value of attribute charter_schools.
-
#elementary_schools ⇒ Object
Returns the value of attribute elementary_schools.
-
#high_schools ⇒ Object
Returns the value of attribute high_schools.
-
#middle_schools ⇒ Object
Returns the value of attribute middle_schools.
-
#name ⇒ Object
(also: #city)
Returns the value of attribute name.
-
#private_schools ⇒ Object
Returns the value of attribute private_schools.
-
#public_schools ⇒ Object
Returns the value of attribute public_schools.
-
#rating ⇒ Object
Returns the value of attribute rating.
-
#state ⇒ Object
Returns the value of attribute state.
-
#total_schools ⇒ Object
Returns the value of attribute total_schools.
Class Method Summary collapse
-
.nearby(state, city, options = {}) ⇒ Object
Returns a list of cities near another city.
-
.overview(state, city) ⇒ Object
Returns information about a city.
Instance Method Summary collapse
-
#districts ⇒ Object
Returns a list of districts in a city.
-
#reviews(options = {}) ⇒ Object
Returns a list of the most recent reviews for any schools in a city.
Methods inherited from Model
Constructor Details
This class inherits a constructor from GreatSchools::Model
Instance Attribute Details
#charter_schools ⇒ Object
Returns the value of attribute charter_schools.
11 12 13 |
# File 'lib/great_schools/city.rb', line 11 def charter_schools @charter_schools end |
#elementary_schools ⇒ Object
Returns the value of attribute elementary_schools.
10 11 12 |
# File 'lib/great_schools/city.rb', line 10 def elementary_schools @elementary_schools end |
#high_schools ⇒ Object
Returns the value of attribute high_schools.
10 11 12 |
# File 'lib/great_schools/city.rb', line 10 def high_schools @high_schools end |
#middle_schools ⇒ Object
Returns the value of attribute middle_schools.
10 11 12 |
# File 'lib/great_schools/city.rb', line 10 def middle_schools @middle_schools end |
#name ⇒ Object Also known as: city
Returns the value of attribute name.
9 10 11 |
# File 'lib/great_schools/city.rb', line 9 def name @name end |
#private_schools ⇒ Object
Returns the value of attribute private_schools.
11 12 13 |
# File 'lib/great_schools/city.rb', line 11 def private_schools @private_schools end |
#public_schools ⇒ Object
Returns the value of attribute public_schools.
11 12 13 |
# File 'lib/great_schools/city.rb', line 11 def public_schools @public_schools end |
#rating ⇒ Object
Returns the value of attribute rating.
9 10 11 |
# File 'lib/great_schools/city.rb', line 9 def @rating end |
#state ⇒ Object
Returns the value of attribute state.
9 10 11 |
# File 'lib/great_schools/city.rb', line 9 def state @state end |
#total_schools ⇒ Object
Returns the value of attribute total_schools.
9 10 11 |
# File 'lib/great_schools/city.rb', line 9 def total_schools @total_schools end |
Class Method Details
.nearby(state, city, options = {}) ⇒ Object
Returns a list of cities near another city.
Attributes
-
state
- Two letter state abbreviation -
city
- Name of city
Options
-
:radius
- Radius in miles to confine search to. Defaults to 15 andcan be in the range 1-100.
-
:sort
- How to sort the results. Defaults to ‘distance’. Otheroptions are 'name' to sort by city name in alphabetical order, and 'rating' to sort by GreatSchool city rating, highest first.
– TODO: handle validations ++
32 33 34 35 36 37 38 |
# File 'lib/great_schools/city.rb', line 32 def nearby(state, city, = {}) .slice!(:radius, :sort) response = GreatSchools::API.get("cities/nearby/#{state.upcase}/#{parameterize(city)}", ) Array.wrap(response).map { |city| new(city.merge(state: state)) } end |
.overview(state, city) ⇒ Object
Returns information about a city.
Attributes
-
state
- Two letter state abbreviation -
city
- Name of city
46 47 48 49 50 |
# File 'lib/great_schools/city.rb', line 46 def overview(state, city) response = GreatSchools::API.get("cities/#{state.upcase}/#{parameterize(city)}") new(response.merge(state: state)) end |
Instance Method Details
#districts ⇒ Object
Returns a list of districts in a city.
57 58 59 |
# File 'lib/great_schools/city.rb', line 57 def districts @districts ||= GreatSchools::District.browse(state, city) end |
#reviews(options = {}) ⇒ Object
Returns a list of the most recent reviews for any schools in a city.
Options
-
:cutoff_age
- Reviews must have been published after this many daysago to be returned.
-
:limit
- Maximum number of reviews to return. This defaults to 5.
68 69 70 |
# File 'lib/great_schools/city.rb', line 68 def reviews( = {}) GreatSchools::Review.for_city(state, name, .slice(:cuttoff_age, :limit)) end |