Class: Nhtsa::ChildSafetySeatInspectionStationLocator::GetByZipCode

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of GetByZipCode.



12
13
14
15
# File 'lib/nhtsa/child_safety_seat_inspection_station_locator.rb', line 12

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

Instance Method Details

#inspection_stationsObject



29
30
31
# File 'lib/nhtsa/child_safety_seat_inspection_station_locator.rb', line 29

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

#urlObject



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/nhtsa/child_safety_seat_inspection_station_locator.rb', line 17

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