sipp 0.1.0 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/README.md +1 -1
- data/lib/sipp/code.rb +63 -18
- data/lib/sipp/dictionary.rb +18 -1
- data/lib/sipp/version.rb +1 -1
- data/lib/sipp.rb +2 -2
- data/sipp.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a759acbd50e83cfbc4294f476ca21048c42286fb
|
4
|
+
data.tar.gz: 91df79cf3188f78777c1495002445c540e60d031
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e699be1f95b5075a45b4b8b54fc1e1ea1c418c32e88e1a202e9659d4e5e1ec4dfa3bfd00ef803ff79555d858cb1acd831e767249381cae6a3dda4748905e3465
|
7
|
+
data.tar.gz: fbe654d6c318cbc133c7a43d60614a800135d093b62a3524eeaa26747f60e33183e108475925961e5048b8e754683f35a2a8560b38e50a2ec50c26217a0f863f
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -33,7 +33,7 @@ Calling `code.validate!` will throw validation errors with exceptions.
|
|
33
33
|
## TODO
|
34
34
|
- add pseudo codes
|
35
35
|
- add van codes
|
36
|
-
- add i18n helpers
|
36
|
+
- add i18n helpers or redo strings into symbols to be i18n-ised
|
37
37
|
- add query methods for common checks (like `.diesel?` etc)
|
38
38
|
|
39
39
|
|
data/lib/sipp/code.rb
CHANGED
@@ -7,7 +7,7 @@ module SIPP
|
|
7
7
|
attr_reader :code
|
8
8
|
|
9
9
|
def initialize(code = nil)
|
10
|
-
@code = code.to_s.upcase
|
10
|
+
@code = code.to_s.strip.upcase
|
11
11
|
|
12
12
|
end
|
13
13
|
|
@@ -15,50 +15,95 @@ module SIPP
|
|
15
15
|
validate_code &&
|
16
16
|
validate_category &&
|
17
17
|
validate_type &&
|
18
|
-
|
18
|
+
validate_transmission_drive &&
|
19
19
|
validate_fuel_ac
|
20
20
|
end
|
21
21
|
|
22
22
|
def valid?
|
23
23
|
validate!
|
24
|
-
rescue CodeError, CategoryError, TypeError,
|
24
|
+
rescue CodeError, CategoryError, TypeError, TransmissionDriveError, FuelACError
|
25
25
|
false
|
26
26
|
end
|
27
27
|
|
28
28
|
def category
|
29
|
-
|
29
|
+
validate_category
|
30
|
+
CATEGORY[code[0]]
|
31
|
+
rescue CategoryError => e
|
32
|
+
nil
|
30
33
|
end
|
31
34
|
|
32
35
|
def type
|
33
|
-
|
36
|
+
validate_type
|
37
|
+
TYPE[code[1]]
|
38
|
+
rescue TypeError => e
|
39
|
+
nil
|
40
|
+
end
|
41
|
+
|
42
|
+
def transmission_drive
|
43
|
+
validate_transmission_drive
|
44
|
+
TRANSMISSION_DRIVE[code[2]]
|
45
|
+
rescue TransmissionDriveError => e
|
46
|
+
nil
|
34
47
|
end
|
35
48
|
|
36
49
|
def transmission
|
37
|
-
|
50
|
+
validate_transmission_drive
|
51
|
+
TRANSMISSION[code[2]]
|
52
|
+
rescue TransmissionDriveError => e
|
53
|
+
nil
|
54
|
+
end
|
55
|
+
|
56
|
+
def transmission_manual?
|
57
|
+
validate_transmission_drive
|
58
|
+
'Manual' == transmission ? true : false # TODO fix magic string
|
59
|
+
rescue TransmissionDriveError => e
|
60
|
+
nil
|
61
|
+
end
|
62
|
+
|
63
|
+
def transmission_auto?
|
64
|
+
validate_transmission_drive
|
65
|
+
'Auto' == transmission ? true : false # TODO fix magic string
|
66
|
+
rescue TransmissionDriveError => e
|
67
|
+
nil
|
68
|
+
end
|
69
|
+
|
70
|
+
def drive
|
71
|
+
validate_transmission_drive
|
72
|
+
DRIVE[code[2]]
|
73
|
+
rescue TransmissionDriveError => e
|
74
|
+
nil
|
38
75
|
end
|
39
76
|
|
40
77
|
def fuel_ac
|
41
|
-
|
78
|
+
validate_fuel_ac
|
79
|
+
FUEL_AC[code[3]]
|
80
|
+
rescue FuelACError => e
|
81
|
+
nil
|
42
82
|
end
|
43
83
|
|
44
84
|
def fuel
|
45
|
-
|
85
|
+
validate_fuel_ac
|
86
|
+
FUEL[code[3]]
|
87
|
+
rescue FuelACError => e
|
88
|
+
nil
|
46
89
|
end
|
47
90
|
|
48
91
|
def ac
|
49
|
-
|
92
|
+
validate_fuel_ac
|
93
|
+
AC[code[3]]
|
94
|
+
rescue FuelACError => e
|
95
|
+
nil
|
50
96
|
end
|
51
97
|
|
52
98
|
def ac?
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
end
|
99
|
+
validate_fuel_ac
|
100
|
+
'Air' == ac ? true : false # TODO fix magic string
|
101
|
+
rescue FuelACError => e
|
102
|
+
nil
|
58
103
|
end
|
59
104
|
|
60
105
|
def to_s
|
61
|
-
[category, type,
|
106
|
+
[category, type, transmission_drive, fuel_ac].join(' - ') if valid?
|
62
107
|
end
|
63
108
|
|
64
109
|
private
|
@@ -87,9 +132,9 @@ module SIPP
|
|
87
132
|
end
|
88
133
|
end
|
89
134
|
|
90
|
-
def
|
91
|
-
if @code[2].blank? || !
|
92
|
-
raise
|
135
|
+
def validate_transmission_drive
|
136
|
+
if @code[2].blank? || !TRANSMISSION_DRIVE.keys.include?(@code[2])
|
137
|
+
raise TransmissionDriveError, :invalid_transmission_drive
|
93
138
|
else
|
94
139
|
true
|
95
140
|
end
|
data/lib/sipp/dictionary.rb
CHANGED
@@ -46,7 +46,7 @@ module SIPP
|
|
46
46
|
'K' => 'Commercial Van/Truck',
|
47
47
|
}
|
48
48
|
|
49
|
-
|
49
|
+
TRANSMISSION_DRIVE = {
|
50
50
|
'M' => 'Manual Unspecified Drive',
|
51
51
|
'N' => 'Manual 4WD',
|
52
52
|
'C' => 'Manual AWD',
|
@@ -54,6 +54,23 @@ module SIPP
|
|
54
54
|
'B' => 'Auto 4WD',
|
55
55
|
'D' => 'Auto AWD',
|
56
56
|
}
|
57
|
+
TRANSMISSION = {
|
58
|
+
'M' => 'Manual',
|
59
|
+
'N' => 'Manual',
|
60
|
+
'C' => 'Manual',
|
61
|
+
'A' => 'Auto',
|
62
|
+
'B' => 'Auto',
|
63
|
+
'D' => 'Auto',
|
64
|
+
}
|
65
|
+
|
66
|
+
DRIVE = {
|
67
|
+
'M' => 'Unspecified',
|
68
|
+
'N' => '4WD',
|
69
|
+
'C' => 'AWD',
|
70
|
+
'A' => 'Unspecified',
|
71
|
+
'B' => '4WD',
|
72
|
+
'D' => 'AWD',
|
73
|
+
}
|
57
74
|
|
58
75
|
FUEL_AC = {
|
59
76
|
'R' => 'Unspecified Fuel/Power With Air',
|
data/lib/sipp/version.rb
CHANGED
data/lib/sipp.rb
CHANGED
@@ -5,11 +5,11 @@ module SIPP
|
|
5
5
|
class CodeError < StandardError; end
|
6
6
|
class CategoryError < StandardError; end
|
7
7
|
class TypeError < StandardError; end
|
8
|
-
class
|
8
|
+
class TransmissionDriveError < StandardError; end
|
9
9
|
class FuelACError < StandardError; end
|
10
10
|
# Your code goes here...
|
11
11
|
end
|
12
12
|
|
13
|
-
require 'active_support/
|
13
|
+
require 'active_support/core_ext/object'
|
14
14
|
require "sipp/code"
|
15
15
|
require "sipp/dictionary"
|
data/sipp.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sipp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Max Buslaev
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-08-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '4.1'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '4.1'
|
69
69
|
description: Translates car SIPP codes into something meaningful
|
70
70
|
email:
|
71
71
|
- max@buslaev.net
|