Class: VinDecoder::Vehicle
- Inherits:
-
Object
- Object
- VinDecoder::Vehicle
show all
- Defined in:
- lib/vin_decoder/vehicle.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(data) ⇒ Vehicle
Returns a new instance of Vehicle.
7
8
9
|
# File 'lib/vin_decoder/vehicle.rb', line 7
def initialize(data)
@raw_data = data || {}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
51
52
53
54
55
56
57
58
|
# File 'lib/vin_decoder/vehicle.rb', line 51
def method_missing(method_name, *args, &block)
return super unless args.empty?
key = lookup_key(method_name)
return super unless key
raw_data[key]
end
|
Instance Attribute Details
#raw_data ⇒ Object
Returns the value of attribute raw_data.
5
6
7
|
# File 'lib/vin_decoder/vehicle.rb', line 5
def raw_data
@raw_data
end
|
Instance Method Details
#[](key) ⇒ Object
39
40
41
|
# File 'lib/vin_decoder/vehicle.rb', line 39
def [](key)
raw_data[key.to_s]
end
|
#engine ⇒ Object
27
28
29
|
# File 'lib/vin_decoder/vehicle.rb', line 27
def engine
raw_data['EngineConfiguration']
end
|
#engine_cylinders ⇒ Object
23
24
25
|
# File 'lib/vin_decoder/vehicle.rb', line 23
def engine_cylinders
raw_data['EngineCylinders']
end
|
#fuel_type ⇒ Object
31
32
33
|
# File 'lib/vin_decoder/vehicle.rb', line 31
def fuel_type
raw_data['FuelTypePrimary']
end
|
#make ⇒ Object
11
12
13
|
# File 'lib/vin_decoder/vehicle.rb', line 11
def make
raw_data['Make']
end
|
#model ⇒ Object
15
16
17
|
# File 'lib/vin_decoder/vehicle.rb', line 15
def model
raw_data['Model']
end
|
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
60
61
62
|
# File 'lib/vin_decoder/vehicle.rb', line 60
def respond_to_missing?(method_name, include_private = false)
lookup_key(method_name) || super
end
|
#to_h ⇒ Object
47
48
49
|
# File 'lib/vin_decoder/vehicle.rb', line 47
def to_h
raw_data.dup
end
|
#trim ⇒ Object
35
36
37
|
# File 'lib/vin_decoder/vehicle.rb', line 35
def trim
raw_data['Trim']
end
|
#valid? ⇒ Boolean
43
44
45
|
# File 'lib/vin_decoder/vehicle.rb', line 43
def valid?
raw_data['ErrorCode'] == '0'
end
|
#year ⇒ Object
19
20
21
|
# File 'lib/vin_decoder/vehicle.rb', line 19
def year
raw_data['ModelYear']
end
|