Class: VinDecoder::Vehicle

Inherits:
Object
  • Object
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_dataObject (readonly)

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

#engineObject



27
28
29
# File 'lib/vin_decoder/vehicle.rb', line 27

def engine
  raw_data['EngineConfiguration']
end

#engine_cylindersObject



23
24
25
# File 'lib/vin_decoder/vehicle.rb', line 23

def engine_cylinders
  raw_data['EngineCylinders']
end

#fuel_typeObject



31
32
33
# File 'lib/vin_decoder/vehicle.rb', line 31

def fuel_type
  raw_data['FuelTypePrimary']
end

#makeObject



11
12
13
# File 'lib/vin_decoder/vehicle.rb', line 11

def make
  raw_data['Make']
end

#modelObject



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

Returns:

  • (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_hObject



47
48
49
# File 'lib/vin_decoder/vehicle.rb', line 47

def to_h
  raw_data.dup
end

#trimObject



35
36
37
# File 'lib/vin_decoder/vehicle.rb', line 35

def trim
  raw_data['Trim']
end

#valid?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/vin_decoder/vehicle.rb', line 43

def valid?
  raw_data['ErrorCode'] == '0'
end

#yearObject



19
20
21
# File 'lib/vin_decoder/vehicle.rb', line 19

def year
  raw_data['ModelYear']
end