Class: FipeApi::Vehicle
Constant Summary collapse
- CAR =
1
- MOTORCYCLE =
2
- TRUCK =
3
Constants inherited from Base
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #get_brands(table = nil) ⇒ Object
- #get_tables ⇒ Object
-
#initialize(id, name) ⇒ Vehicle
constructor
A new instance of Vehicle.
- #name_id ⇒ Object
Constructor Details
#initialize(id, name) ⇒ Vehicle
Returns a new instance of Vehicle.
10 11 12 13 |
# File 'lib/fipe_api/resources/vehicle.rb', line 10 def initialize(id, name) self.id = id self.name = name end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
7 8 9 |
# File 'lib/fipe_api/resources/vehicle.rb', line 7 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/fipe_api/resources/vehicle.rb', line 8 def name @name end |
Class Method Details
Instance Method Details
#get_brands(table = nil) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/fipe_api/resources/vehicle.rb', line 25 def get_brands(table = nil) if table.nil? table = Table.latest(self) end response = HTTP.post("http://veiculos.fipe.org.br/api/veiculos/ConsultarMarcas", headers: HEADERS, params: { codigoTabelaReferencia: table.id, codigoTipoVeiculo: self.id }, body: {}.to_json).to_s brands_hash = JSON.parse(response) brands_result = [] brands_hash.each do |brand| brands_result << Brand.new(brand["Value"], brand["Label"], table, self) end brands_result end |
#get_tables ⇒ Object
21 22 23 |
# File 'lib/fipe_api/resources/vehicle.rb', line 21 def get_tables Table.all(self) end |
#name_id ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/fipe_api/resources/vehicle.rb', line 40 def name_id case id when CAR return "carro" when MOTORCYCLE return "moto" when TRUCK return "caminhao" end end |