Class: GreatSchools::City

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

Overview

GreatSchools City

– TODO: add method to grab nearby schools using GreatSchools::School#nearby with the city and state options. ++

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

#charter_schoolsObject

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_schoolsObject

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_schoolsObject

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_schoolsObject

Returns the value of attribute middle_schools.



10
11
12
# File 'lib/great_schools/city.rb', line 10

def middle_schools
  @middle_schools
end

#nameObject 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_schoolsObject

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_schoolsObject

Returns the value of attribute public_schools.



11
12
13
# File 'lib/great_schools/city.rb', line 11

def public_schools
  @public_schools
end

#ratingObject

Returns the value of attribute rating.



9
10
11
# File 'lib/great_schools/city.rb', line 9

def rating
  @rating
end

#stateObject

Returns the value of attribute state.



9
10
11
# File 'lib/great_schools/city.rb', line 9

def state
  @state
end

#total_schoolsObject

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 and

    can be in the range 1-100.
    
  • :sort - How to sort the results. Defaults to ‘distance’. Other

    options 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, options = {})
  options.slice!(:radius, :sort)

  response = GreatSchools::API.get("cities/nearby/#{state.upcase}/#{parameterize(city)}", options)

  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

#districtsObject

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 days

    ago 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(options = {})
  GreatSchools::Review.for_city(state, name, options.slice(:cuttoff_age, :limit))
end