Class: SIPP::Code
Constant Summary
collapse
- SEPARATOR =
' - '
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.
10
11
12
13
|
# File 'lib/sipp/code.rb', line 10
def initialize(code = nil)
@code = code.to_s.strip.upcase
end
|
Instance Attribute Details
#code ⇒ Object
Returns the value of attribute code.
8
9
10
|
# File 'lib/sipp/code.rb', line 8
def code
@code
end
|
Instance Method Details
#ac ⇒ Object
92
93
94
95
96
97
|
# File 'lib/sipp/code.rb', line 92
def ac
validate_fuel_ac
Ac.new AC[code[3]]
rescue FuelACError => e
nil
end
|
#ac? ⇒ Boolean
99
100
101
102
103
104
|
# File 'lib/sipp/code.rb', line 99
def ac?
validate_fuel_ac
:air == ac.to_sym ? true : false
rescue FuelACError => e
nil
end
|
#as_json(options = nil) ⇒ Object
114
115
116
|
# File 'lib/sipp/code.rb', line 114
def as_json(options = nil)
[category, type, transmission, drive, fuel, ac].compact.map(&:as_json).inject(&:merge).merge({code: @code})
end
|
#category ⇒ Object
29
30
31
32
33
34
|
# File 'lib/sipp/code.rb', line 29
def category
validate_category
Category.new CATEGORY[code[0]]
rescue CategoryError => e
nil
end
|
#drive ⇒ Object
71
72
73
74
75
76
|
# File 'lib/sipp/code.rb', line 71
def drive
validate_transmission_drive
Drive.new DRIVE[code[2]]
rescue TransmissionDriveError => e
nil
end
|
#fuel ⇒ Object
85
86
87
88
89
90
|
# File 'lib/sipp/code.rb', line 85
def fuel
validate_fuel_ac
Fuel.new FUEL[code[3]]
rescue FuelACError => e
nil
end
|
#fuel_ac ⇒ Object
78
79
80
81
82
83
|
# File 'lib/sipp/code.rb', line 78
def fuel_ac
validate_fuel_ac
FuelAC.new FUEL_AC[code[3]]
rescue FuelACError => e
nil
end
|
#to_s ⇒ Object
108
109
110
111
112
|
# File 'lib/sipp/code.rb', line 108
def to_s
[category, type, transmission_drive, fuel_ac].map{|c| c.nil? ? '#N/A' : c}.join(SEPARATOR)
rescue CodeError, CategoryError, TypeError, TransmissionDriveError, FuelACError
''
end
|
#transmission ⇒ Object
50
51
52
53
54
55
|
# File 'lib/sipp/code.rb', line 50
def transmission
validate_transmission_drive
Transmission.new TRANSMISSION[code[2]]
rescue TransmissionDriveError => e
nil
end
|
#transmission_auto? ⇒ Boolean
64
65
66
67
68
69
|
# File 'lib/sipp/code.rb', line 64
def transmission_auto?
validate_transmission_drive
:auto == transmission.to_sym ? true : false
rescue TransmissionDriveError => e
nil
end
|
#transmission_drive ⇒ Object
43
44
45
46
47
48
|
# File 'lib/sipp/code.rb', line 43
def transmission_drive
validate_transmission_drive
TransmissionDrive.new TRANSMISSION_DRIVE[code[2]]
rescue TransmissionDriveError => e
nil
end
|
#transmission_manual? ⇒ Boolean
57
58
59
60
61
62
|
# File 'lib/sipp/code.rb', line 57
def transmission_manual?
validate_transmission_drive
:manual == transmission.to_sym ? true : false
rescue TransmissionDriveError => e
nil
end
|
#type ⇒ Object
36
37
38
39
40
41
|
# File 'lib/sipp/code.rb', line 36
def type
validate_type
Type.new TYPE[code[1]]
rescue TypeError => e
nil
end
|
#valid? ⇒ Boolean
23
24
25
26
27
|
# File 'lib/sipp/code.rb', line 23
def valid?
validate!
rescue CodeError, CategoryError, TypeError, TransmissionDriveError, FuelACError
false
end
|
#validate! ⇒ Object
15
16
17
18
19
20
21
|
# File 'lib/sipp/code.rb', line 15
def validate!
validate_code &&
validate_category &&
validate_type &&
validate_transmission_drive &&
validate_fuel_ac
end
|