Class: Nhtsa::ChildSafetySeatInspectionStationLocator::GetByState

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

Instance Method Summary collapse

Constructor Details

#initialize(state_abbreviation, filters = {spanish: false, cpsweek: false}) ⇒ GetByState

Returns a new instance of GetByState.



35
36
37
38
# File 'lib/nhtsa/child_safety_seat_inspection_station_locator.rb', line 35

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

Instance Method Details

#inspection_stationsObject



52
53
54
# File 'lib/nhtsa/child_safety_seat_inspection_station_locator.rb', line 52

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

#urlObject



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/nhtsa/child_safety_seat_inspection_station_locator.rb', line 40

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