Class: SIPP::Code

Inherits:
Object
  • Object
show all
Includes:
Dictionary
Defined in:
lib/sipp/code.rb

Constant Summary

Constants included from Dictionary

Dictionary::AC, Dictionary::CATEGORY, Dictionary::DRIVE, Dictionary::FUEL, Dictionary::FUEL_AC, Dictionary::TRANSMISSION, Dictionary::TRANSMISSION_DRIVE, Dictionary::TYPE

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code = nil) ⇒ Code

Returns a new instance of Code.



9
10
11
12
# File 'lib/sipp/code.rb', line 9

def initialize(code = nil)
  @code = code.to_s.strip.upcase

end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



7
8
9
# File 'lib/sipp/code.rb', line 7

def code
  @code
end

Instance Method Details

#acObject



91
92
93
94
95
96
# File 'lib/sipp/code.rb', line 91

def ac
  validate_fuel_ac
  AC[code[3]]
rescue FuelACError => e
  nil
end

#ac?Boolean

Returns:

  • (Boolean)


98
99
100
101
102
103
# File 'lib/sipp/code.rb', line 98

def ac?
  validate_fuel_ac
  'Air' == ac ? true : false # TODO fix magic string
rescue FuelACError => e
  nil
end

#categoryObject



28
29
30
31
32
33
# File 'lib/sipp/code.rb', line 28

def category
  validate_category
  CATEGORY[code[0]]
rescue CategoryError => e
  nil
end

#driveObject



70
71
72
73
74
75
# File 'lib/sipp/code.rb', line 70

def drive
  validate_transmission_drive
  DRIVE[code[2]]
rescue TransmissionDriveError => e
  nil
end

#fuelObject



84
85
86
87
88
89
# File 'lib/sipp/code.rb', line 84

def fuel
  validate_fuel_ac
  FUEL[code[3]]
rescue FuelACError => e
  nil
end

#fuel_acObject



77
78
79
80
81
82
# File 'lib/sipp/code.rb', line 77

def fuel_ac
  validate_fuel_ac
  FUEL_AC[code[3]]
rescue FuelACError => e
  nil
end

#to_sObject



105
106
107
108
109
# File 'lib/sipp/code.rb', line 105

def to_s
  [category, type, transmission_drive, fuel_ac].map{|c| c.nil? ? '#N/A' : c}.join(' - ')
rescue CodeError, CategoryError, TypeError, TransmissionDriveError, FuelACError
  ''
end

#transmissionObject



49
50
51
52
53
54
# File 'lib/sipp/code.rb', line 49

def transmission
  validate_transmission_drive
  TRANSMISSION[code[2]]
rescue TransmissionDriveError => e
  nil
end

#transmission_auto?Boolean

Returns:

  • (Boolean)


63
64
65
66
67
68
# File 'lib/sipp/code.rb', line 63

def transmission_auto?
  validate_transmission_drive
  'Auto' == transmission ? true : false # TODO fix magic string
rescue TransmissionDriveError => e
  nil
end

#transmission_driveObject



42
43
44
45
46
47
# File 'lib/sipp/code.rb', line 42

def transmission_drive
  validate_transmission_drive
  TRANSMISSION_DRIVE[code[2]]
rescue TransmissionDriveError => e
  nil
end

#transmission_manual?Boolean

Returns:

  • (Boolean)


56
57
58
59
60
61
# File 'lib/sipp/code.rb', line 56

def transmission_manual?
  validate_transmission_drive
  'Manual' == transmission ? true : false # TODO fix magic string
rescue TransmissionDriveError => e
  nil
end

#typeObject



35
36
37
38
39
40
# File 'lib/sipp/code.rb', line 35

def type
  validate_type
  TYPE[code[1]]
rescue TypeError => e
  nil
end

#valid?Boolean

Returns:

  • (Boolean)


22
23
24
25
26
# File 'lib/sipp/code.rb', line 22

def valid?
  validate!
rescue CodeError, CategoryError, TypeError, TransmissionDriveError, FuelACError
  false
end

#validate!Object



14
15
16
17
18
19
20
# File 'lib/sipp/code.rb', line 14

def validate!
  validate_code &&
    validate_category &&
    validate_type &&
    validate_transmission_drive &&
    validate_fuel_ac
end