Class: Nhtsa::SafetyRatings::Models
- Inherits:
-
Object
- Object
- Nhtsa::SafetyRatings::Models
- Defined in:
- lib/nhtsa/safety_ratings/models.rb
Instance Method Summary collapse
-
#initialize(year, manufacturer) ⇒ Models
constructor
A new instance of Models.
- #model_names ⇒ Object
- #models ⇒ Object
- #to_s ⇒ Object
- #url ⇒ Object
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_names ⇒ Object
18 19 20 |
# File 'lib/nhtsa/safety_ratings/models.rb', line 18 def model_names @models.map(&:model_name) end |
#models ⇒ Object
14 15 16 |
# File 'lib/nhtsa/safety_ratings/models.rb', line 14 def models @models end |
#to_s ⇒ Object
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 |
#url ⇒ Object
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 |