Class: Nhtsa::SafetyRatings::Trims

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

Instance Method Summary collapse

Constructor Details

#initialize(year, manufacturer, model) ⇒ Trims

Returns a new instance of Trims.



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

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

Instance Method Details

#descriptionsObject



31
32
33
# File 'lib/nhtsa/safety_ratings/trims.rb', line 31

def descriptions
  @trims.map(&:trim_description)
end

#idsObject



35
36
37
# File 'lib/nhtsa/safety_ratings/trims.rb', line 35

def ids
  @trims.map(&:trim_id)
end

#manufacturerObject



19
20
21
# File 'lib/nhtsa/safety_ratings/trims.rb', line 19

def manufacturer
  @manufacturer
end

#modelObject



23
24
25
# File 'lib/nhtsa/safety_ratings/trims.rb', line 23

def model
  @model
end

#trimsObject



27
28
29
# File 'lib/nhtsa/safety_ratings/trims.rb', line 27

def trims
  @trims
end

#urlObject



11
12
13
# File 'lib/nhtsa/safety_ratings/trims.rb', line 11

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

#yearObject



15
16
17
# File 'lib/nhtsa/safety_ratings/trims.rb', line 15

def year
  @year
end