Class: FipeApi::Model
Instance Attribute Summary collapse
-
#brand ⇒ Object
Returns the value of attribute brand.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #get_years(table = nil) ⇒ Object
-
#initialize(id, name, brand) ⇒ Model
constructor
A new instance of Model.
Constructor Details
#initialize(id, name, brand) ⇒ Model
Returns a new instance of Model.
7 8 9 10 11 |
# File 'lib/fipe_api/resources/model.rb', line 7 def initialize(id, name, brand) self.id = id self.name = name self.brand = brand end |
Instance Attribute Details
#brand ⇒ Object
Returns the value of attribute brand.
5 6 7 |
# File 'lib/fipe_api/resources/model.rb', line 5 def brand @brand end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/fipe_api/resources/model.rb', line 3 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/fipe_api/resources/model.rb', line 4 def name @name end |
Instance Method Details
#get_years(table = nil) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/fipe_api/resources/model.rb', line 13 def get_years(table = nil) if table.nil? table = Table.latest(self.brand.vehicle) end response = HTTP.post("http://veiculos.fipe.org.br/api/veiculos/ConsultarAnoModelo", params: { codigoTabelaReferencia: table.id, codigoTipoVeiculo: self.brand.vehicle.id, codigoMarca: self.brand.id, codigoModelo: self.id, }, body: {}.to_json).to_s years_hash = JSON.parse(response) years_result = [] years_hash.each do |year| years_result << Year.new(year["Value"], year["Label"], self) end years_result end |