class Nhtsa::SafetyRatings::Ratings
Public Class Methods
new(*vehicle_ids)
click to toggle source
# File lib/nhtsa/safety_ratings/ratings.rb, line 4 def initialize(*vehicle_ids) raise ArgumentError, "At Least 1 vehicle id is required" if vehicle_ids.empty? @vehicle_ids = Array(vehicle_ids).flatten @ratings = @vehicle_ids.collect{|vehicle_id| Rating.new(JSON.parse(open(url(vehicle_id)).read)["Results"].first)} end
Public Instance Methods
ratings()
click to toggle source
# File lib/nhtsa/safety_ratings/ratings.rb, line 14 def ratings @ratings end
to_s()
click to toggle source
# File lib/nhtsa/safety_ratings/ratings.rb, line 22 def to_s @ratings.map(&:to_s).join("\n#{'='*50}\n\n") end
url(vehicle_id)
click to toggle source
# File lib/nhtsa/safety_ratings/ratings.rb, line 10 def url(vehicle_id) "#{BASE_URI}#{END_POINT}/VehicleId/#{vehicle_id}#{DEFAULT_PARAMS}" end
values()
click to toggle source
# File lib/nhtsa/safety_ratings/ratings.rb, line 18 def values @ratings.map(&:values) end