Class: Nhtsa::SafetyRatings::Models

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

Instance Method Summary collapse

Constructor Details

#initialize(year, manufacturer) ⇒ Models

Returns a new instance of Models.



4
5
6
7
8
# File 'lib/nhtsa/safety_ratings/models.rb', line 4

def initialize(year, manufacturer)
  @year = Year.new(year)
  @manufacturer = Manufacturer.new(year, manufacturer)
  @models = JSON.parse(open(url).read)["Results"].collect{|model| Model.new(@year, @manufacturer, model["Model"])}
end

Instance Method Details

#model_namesObject



18
19
20
# File 'lib/nhtsa/safety_ratings/models.rb', line 18

def model_names
  @models.map(&:model_name)
end

#modelsObject



14
15
16
# File 'lib/nhtsa/safety_ratings/models.rb', line 14

def models
  @models
end

#to_sObject



22
23
24
# File 'lib/nhtsa/safety_ratings/models.rb', line 22

def to_s
  @models.inject(""){|model_string, model| model_string << "#{model}\n"}
end

#urlObject



10
11
12
# File 'lib/nhtsa/safety_ratings/models.rb', line 10

def url
  BASE_URI + END_POINT + "/#{@year}/#{URI.encode(@manufacturer.name)}" + DEFAULT_PARAMS
end