Class: Nhtsa::ChildSafetySeatInspectionStationLocator::GetByZipCode

Inherits:
Object
  • Object
show all
Defined in:
lib/nhtsa/child_safety_seat_inspection_station_locator/get_by_zip_code.rb

Instance Method Summary collapse

Constructor Details

#initialize(zip_code, filters = {:spanish => false, :cpsweek => false}) ⇒ GetByZipCode



4
5
6
7
# File 'lib/nhtsa/child_safety_seat_inspection_station_locator/get_by_zip_code.rb', line 4

def initialize(zip_code, filters = {:spanish => false, :cpsweek => false})
  @zip_code = zip_code
  @filters = filters
end

Instance Method Details

#inspection_stationsObject



21
22
23
# File 'lib/nhtsa/child_safety_seat_inspection_station_locator/get_by_zip_code.rb', line 21

def inspection_stations
  JSON.parse(open(url).read)["Results"]
end

#urlObject



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/nhtsa/child_safety_seat_inspection_station_locator/get_by_zip_code.rb', line 9

def url
  if @filters[:spanish] && @filters[:cpsweek]
    BASE_URI + END_POINT + "/zip/#{@zip_code}" + CPS_WEEK + SPANISH + DEFAULT_PARAMS
  elsif @filters[:spanish]
    BASE_URI + END_POINT + "/zip/#{@zip_code}" + SPANISH + DEFAULT_PARAMS
  elsif @filters[:cpsweek]
    BASE_URI + END_POINT + "/zip/#{@zip_code}" + CPS_WEEK + DEFAULT_PARAMS
  else
    BASE_URI + END_POINT + "/zip/#{@zip_code}" + DEFAULT_PARAMS
  end
end