Class: Edmunds::Vehicle::Specification::Model::Model
- Inherits:
-
Object
- Object
- Edmunds::Vehicle::Specification::Model::Model
- Defined in:
- lib/edmunds/vehicle/specification/model.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#years ⇒ Object
readonly
Returns the value of attribute years.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attributes) ⇒ Model
constructor
A new instance of Model.
Constructor Details
#initialize(attributes) ⇒ Model
Returns a new instance of Model.
13 14 15 16 17 |
# File 'lib/edmunds/vehicle/specification/model.rb', line 13 def initialize(attributes) @id = attributes['id'] @name = attributes['name'] @years = attributes['years'].map { |json| Edmunds::Vehicle::Specification::ModelYear::ModelYear.new(json) } if attributes.key?('years') end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
11 12 13 |
# File 'lib/edmunds/vehicle/specification/model.rb', line 11 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/edmunds/vehicle/specification/model.rb', line 11 def name @name end |
#years ⇒ Object (readonly)
Returns the value of attribute years.
11 12 13 |
# File 'lib/edmunds/vehicle/specification/model.rb', line 11 def years @years end |
Class Method Details
.find(make_name, model_name, api_params = {}) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/edmunds/vehicle/specification/model.rb', line 19 def self.find(make_name, model_name, api_params = {}) response = Edmunds::Api.get("#{MODEL_API_URL}/#{make_name}/#{model_name}") do |request| request.raw_parameters = api_params request.allowed_parameters = { submodel: Edmunds::Vehicle::SUBMODEL_REGEX, category: Edmunds::Vehicle::VEHICLE_CATEGORIES, state: %w[new used future], year: ((1990.to_s)..(Date.current.year.to_s)), view: %w[basic full], fmt: %w[json] } request.default_parameters = { view: 'basic', fmt: 'json' } request.required_parameters = %w[fmt] end attributes = JSON.parse(response.body) new(attributes) end |