sipp 0.1.6 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +58 -1
- data/config/locales/en.yml +4 -0
- data/config/locales/ru.yml +4 -0
- data/lib/sipp/code.rb +4 -2
- data/lib/sipp/dictionary.rb +1 -1
- data/lib/sipp/extended.rb +114 -0
- data/lib/sipp/extended_dictionary.rb +57 -0
- data/lib/sipp/inverted.rb +15 -0
- data/lib/sipp/inverted_dictionary.rb +38 -0
- data/lib/sipp/version.rb +1 -1
- data/lib/sipp.rb +4 -0
- data/sipp.gemspec +1 -1
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f19fbec80dadd3c4c7d351ad605666722a7f628c
|
4
|
+
data.tar.gz: fde3f3ccec2ac4c43bc0c345f7ddc26004435e60
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5043f858559c2019a89b2795ec381617a172d5aebe78bf32d9543a463a8c991d237c7f775acf611515aac7eaac9df26abd4bd78aa4b750ea05a00ad9aa0e476a
|
7
|
+
data.tar.gz: 6dd7d7fd130c6607cfbc0b93c49b554ca4610930403992c3a730d110f10af5368295608ca78c04e6efe42754c14fd1ee34464a15430da68013840675d6e53e37
|
data/README.md
CHANGED
@@ -93,12 +93,69 @@ ua:
|
|
93
93
|
manual: МКПП
|
94
94
|
auto: АКПП
|
95
95
|
```
|
96
|
+
## Inverted
|
97
|
+
_A very early beta. But beta than nothin'_
|
98
|
+
|
99
|
+
It's also able to generate a SIPP code from car capabilities.
|
100
|
+
The capabilities are expected in the same format as produced by `#as_json`.
|
101
|
+
If something invalid is supplied it generates `'*'`.
|
102
|
+
|
103
|
+
```ruby
|
104
|
+
SIPP::Inverted.generate({ category: :compact, type: :two_four_door, transmission: :manual, drive: :unspecified, fuel: :petrol, ac: :air})
|
105
|
+
# => 'CCMV'
|
106
|
+
SIPP::Inverted.generate({ category: :compact, type: :two_four_door, fuel: :petrol, ac: :air })
|
107
|
+
# => 'CC*V'
|
108
|
+
```
|
109
|
+
|
110
|
+
## Extended
|
111
|
+
|
112
|
+
Works most similar to Inverted but produces a more consistent approach to encoding car capabilities.
|
113
|
+
|
114
|
+
Generates an Extended-SIPP code from capabilities provided and translates capabilities list into an Extended-SIPP code.
|
115
|
+
|
116
|
+
Should be tried and discussed.
|
117
|
+
|
118
|
+
```ruby
|
119
|
+
SIPP::Extended.new('CCMFDA55').as_json
|
120
|
+
|
121
|
+
{
|
122
|
+
category: :compact,
|
123
|
+
type: :two_four_door,
|
124
|
+
transmission: :manual,
|
125
|
+
drive: :front,
|
126
|
+
fuel: :diesel,
|
127
|
+
ac: :air,
|
128
|
+
doors: 5,
|
129
|
+
seats: 5,
|
130
|
+
bags_big: :unspecified,
|
131
|
+
bags_small: :unspecified,
|
132
|
+
}
|
133
|
+
|
134
|
+
SIPP::Extended.new('CBMFPN2234').as_json
|
135
|
+
{
|
136
|
+
category: :compact,
|
137
|
+
type: :two_three_door,
|
138
|
+
transmission: :manual,
|
139
|
+
drive: :front,
|
140
|
+
fuel: :petrol,
|
141
|
+
ac: :no_air,
|
142
|
+
doors: 2,
|
143
|
+
seats: 2,
|
144
|
+
bags_big: 3,
|
145
|
+
bags_small: 4,
|
146
|
+
}
|
147
|
+
|
148
|
+
```
|
96
149
|
|
97
150
|
## TODO
|
98
151
|
- [x] add i18n helpers or redo strings into symbols to be i18n-sed
|
152
|
+
- [x] add SIPP code generation from car capabilities
|
153
|
+
- [ ] add input validation of some kind?
|
154
|
+
- [x] add Extended SIPP codes
|
155
|
+
- [ ] add more adequate tests
|
156
|
+
- [ ] add query methods for common checks (like `.diesel?` etc)
|
99
157
|
- [ ] add pseudo codes
|
100
158
|
- [ ] add van codes
|
101
|
-
- [ ] add query methods for common checks (like `.diesel?` etc)
|
102
159
|
|
103
160
|
|
104
161
|
## Development
|
data/config/locales/en.yml
CHANGED
@@ -55,11 +55,15 @@ en:
|
|
55
55
|
transmission:
|
56
56
|
manual: Manual
|
57
57
|
auto: Auto
|
58
|
+
robot: Robot
|
58
59
|
|
59
60
|
drive:
|
60
61
|
unspecified: Unspecified
|
61
62
|
four_wd: 4WD
|
62
63
|
awd: AWD
|
64
|
+
single: Single
|
65
|
+
front: Front
|
66
|
+
rear: Rear
|
63
67
|
|
64
68
|
fuel_ac:
|
65
69
|
unspecified_air: Unspecified Fuel/Power With Air
|
data/config/locales/ru.yml
CHANGED
@@ -55,11 +55,15 @@ ru:
|
|
55
55
|
transmission:
|
56
56
|
manual: МКПП
|
57
57
|
auto: АКПП
|
58
|
+
robot: Робот
|
58
59
|
|
59
60
|
drive:
|
60
61
|
unspecified: привод не указан
|
61
62
|
four_wd: 4WD
|
62
63
|
awd: AWD
|
64
|
+
single: Монопривод
|
65
|
+
front: Передний
|
66
|
+
rear: Задний
|
63
67
|
|
64
68
|
fuel_ac:
|
65
69
|
unspecified_air: топливо не указано, кондиционер
|
data/lib/sipp/code.rb
CHANGED
@@ -103,14 +103,16 @@ module SIPP
|
|
103
103
|
nil
|
104
104
|
end
|
105
105
|
|
106
|
+
SEPARATOR = ' - '
|
107
|
+
|
106
108
|
def to_s
|
107
|
-
[category, type, transmission_drive, fuel_ac].map{|c| c.nil? ? '#N/A' : c}.join(
|
109
|
+
[category, type, transmission_drive, fuel_ac].map{|c| c.nil? ? '#N/A' : c}.join(SEPARATOR)
|
108
110
|
rescue CodeError, CategoryError, TypeError, TransmissionDriveError, FuelACError
|
109
111
|
''
|
110
112
|
end
|
111
113
|
|
112
114
|
def as_json(options = nil)
|
113
|
-
[category, type, transmission, drive, fuel, ac].map(&:as_json).inject(&:merge).merge({code: @code})
|
115
|
+
[category, type, transmission, drive, fuel, ac].compact.map(&:as_json).inject(&:merge).merge({code: @code})
|
114
116
|
end
|
115
117
|
|
116
118
|
private
|
data/lib/sipp/dictionary.rb
CHANGED
@@ -0,0 +1,114 @@
|
|
1
|
+
require 'sipp/extended_dictionary'
|
2
|
+
module SIPP
|
3
|
+
|
4
|
+
class Extended
|
5
|
+
include ExtendedDictionary
|
6
|
+
|
7
|
+
def self.generate(capabilities)
|
8
|
+
capabilities = capabilities.inject({}) do |caps, (k, v)|
|
9
|
+
val = v.respond_to?(:to_sym) ? v.to_sym : v
|
10
|
+
caps[k&.to_sym] = val
|
11
|
+
caps
|
12
|
+
end
|
13
|
+
category = CATEGORY[capabilities[:category]]
|
14
|
+
type = TYPE[capabilities[:type]]
|
15
|
+
transmission = TRANSMISSION[capabilities[:transmission]]
|
16
|
+
drive = DRIVE[capabilities[:drive]]
|
17
|
+
fuel = FUEL[capabilities[:fuel]]
|
18
|
+
ac = AC[capabilities[:ac]]
|
19
|
+
capabilities[:bags_big] = capabilities.delete(:bags) unless capabilities[:bags].nil?
|
20
|
+
%i[doors seats bags_big bags_small].each do |cap|
|
21
|
+
capabilities[cap] = nil if :unspecified == capabilities[cap]
|
22
|
+
end
|
23
|
+
|
24
|
+
[
|
25
|
+
category, type, transmission, drive, fuel, ac,
|
26
|
+
capabilities[:doors],
|
27
|
+
capabilities[:seats],
|
28
|
+
(capabilities[:bags_big] || capabilities[:bags]),
|
29
|
+
capabilities[:bags_small],
|
30
|
+
].map{|cap| cap || '*'}.join
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
attr_reader :code
|
35
|
+
def initialize(code = nil)
|
36
|
+
@code = code.to_s.strip.upcase
|
37
|
+
.ljust(10, '*') # pad everything absent as :unspecified
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
def category
|
43
|
+
Category.new CATEGORY.invert[code[0]]
|
44
|
+
end
|
45
|
+
|
46
|
+
def type
|
47
|
+
Type.new TYPE.invert[code[1]]
|
48
|
+
end
|
49
|
+
|
50
|
+
def transmission
|
51
|
+
Transmission.new TRANSMISSION.invert[code[2]]
|
52
|
+
end
|
53
|
+
def drive
|
54
|
+
Drive.new DRIVE.invert[code[3]]
|
55
|
+
end
|
56
|
+
def fuel
|
57
|
+
Fuel.new FUEL.invert[code[4]]
|
58
|
+
end
|
59
|
+
def ac
|
60
|
+
Ac.new AC.invert[code[5]]
|
61
|
+
end
|
62
|
+
def doors
|
63
|
+
result = code[6]&.to_i
|
64
|
+
if result.zero?
|
65
|
+
:unspecified
|
66
|
+
else
|
67
|
+
result
|
68
|
+
end
|
69
|
+
end
|
70
|
+
def seats
|
71
|
+
result = code[7]&.to_i
|
72
|
+
if result.zero?
|
73
|
+
:unspecified
|
74
|
+
else
|
75
|
+
result
|
76
|
+
end
|
77
|
+
end
|
78
|
+
def bags
|
79
|
+
result = code[8]&.to_i
|
80
|
+
if result.zero?
|
81
|
+
:unspecified
|
82
|
+
else
|
83
|
+
result
|
84
|
+
end
|
85
|
+
end
|
86
|
+
alias_method :bags_big, :bags
|
87
|
+
def bags_small
|
88
|
+
result = code[9]&.to_i
|
89
|
+
if result.zero?
|
90
|
+
:unspecified
|
91
|
+
else
|
92
|
+
result
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def to_s
|
97
|
+
[
|
98
|
+
category, type, transmission, drive, fuel, ac,
|
99
|
+
doors, seats, bags_big, bags_small,
|
100
|
+
].join(Code::SEPARATOR)
|
101
|
+
end
|
102
|
+
|
103
|
+
def as_json(options = nil)
|
104
|
+
|
105
|
+
[category, type, transmission, drive, fuel, ac].compact.map(&:as_json).inject(&:merge).merge(
|
106
|
+
{
|
107
|
+
doors: doors,
|
108
|
+
seats: seats,
|
109
|
+
bags_big: bags,
|
110
|
+
bags_small: bags_small
|
111
|
+
})
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module SIPP
|
2
|
+
WILDCARDS = {
|
3
|
+
nil => '*',
|
4
|
+
:unspecified => '*',
|
5
|
+
}
|
6
|
+
module ExtendedDictionary
|
7
|
+
# SIPP-compatible category
|
8
|
+
CATEGORY = SIPP::Code::CATEGORY.invert.merge(WILDCARDS)
|
9
|
+
|
10
|
+
# SIPP-compatible body type
|
11
|
+
TYPE = SIPP::Code::TYPE.invert.merge(WILDCARDS)
|
12
|
+
|
13
|
+
# Transmission type. SIPP-compatible but extended with robot/tiptronic (I wonder if anyone needs it)
|
14
|
+
TRANSMISSION = {
|
15
|
+
manual: 'M',
|
16
|
+
auto: 'A',
|
17
|
+
robot: 'R', # variations of robot/tiptronic etc
|
18
|
+
}.merge(WILDCARDS)
|
19
|
+
|
20
|
+
# Drive type. Incompatible with SIPP because the original SIPP is completely weird and more transmission-oriented
|
21
|
+
DRIVE = {
|
22
|
+
single: 'S',
|
23
|
+
front: 'F',
|
24
|
+
rear: 'R',
|
25
|
+
all: 'A', # AWD
|
26
|
+
fwd: 'X', # 4x4
|
27
|
+
}.merge(WILDCARDS)
|
28
|
+
|
29
|
+
# Fuel type. Mostly compatible with SIPP but you know... Made more human-guessable
|
30
|
+
FUEL = {
|
31
|
+
compressed_gas: "G",
|
32
|
+
diesel: "D",
|
33
|
+
electric: "E",
|
34
|
+
electric_plus: "C",
|
35
|
+
ethanol: "U",
|
36
|
+
hybrid: "H",
|
37
|
+
hybrid_plug_in: "I",
|
38
|
+
hydrogen: "A",
|
39
|
+
multi_fuel: "M",
|
40
|
+
petrol: "P",
|
41
|
+
}.merge(WILDCARDS)
|
42
|
+
|
43
|
+
# Most probably is subject to change in the future
|
44
|
+
# Surprisingly is compatible with SIPP
|
45
|
+
AC = {
|
46
|
+
multi_zone: 'M',
|
47
|
+
present: 'A',
|
48
|
+
absent: 'N',
|
49
|
+
false => 'N',
|
50
|
+
true => 'A',
|
51
|
+
air: 'A',
|
52
|
+
no_air: 'N',
|
53
|
+
}.merge(WILDCARDS)
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'sipp/inverted_dictionary'
|
2
|
+
module SIPP
|
3
|
+
class Inverted
|
4
|
+
include InvertedDictionary
|
5
|
+
|
6
|
+
def self.generate(capabilities)
|
7
|
+
category = CATEGORY[capabilities[:category]]
|
8
|
+
type = TYPE[capabilities[:type]]
|
9
|
+
transmission_drive = TRANSMISSION_DRIVE[[capabilities[:transmission], (capabilities[:drive] || :unspecified)]]
|
10
|
+
fuel_ac = FUEL_AC[[(capabilities[:fuel] || :unspecified), capabilities[:ac]]]
|
11
|
+
|
12
|
+
[category, type, transmission_drive, fuel_ac].map{|cap| cap || '*'}.join
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module SIPP
|
2
|
+
module InvertedDictionary
|
3
|
+
CATEGORY = SIPP::Code::CATEGORY.invert
|
4
|
+
|
5
|
+
TYPE = SIPP::Code::TYPE.invert
|
6
|
+
|
7
|
+
TRANSMISSION_DRIVE = {
|
8
|
+
[:manual, :unspecified] => "M",
|
9
|
+
[:manual, :four_wd] => "N",
|
10
|
+
[:manual, :awd] => "C",
|
11
|
+
[:auto, :unspecified] => "A",
|
12
|
+
[:auto, :four_wd] => "B",
|
13
|
+
[:auto, :awd] => "D"
|
14
|
+
}
|
15
|
+
|
16
|
+
FUEL_AC = {
|
17
|
+
[:unspecified, :air] => "R",
|
18
|
+
[:unspecified, :no_air] => "N",
|
19
|
+
[:diesel, :air] => "D",
|
20
|
+
[:diesel, :no_air] => "Q",
|
21
|
+
[:hybrid, :air] => "H",
|
22
|
+
[:hybrid_plug_in, :air] => "I",
|
23
|
+
[:electric, :air] => "E",
|
24
|
+
[:electric_plus, :air] => "C",
|
25
|
+
[:compressed_gas, :air] => "L",
|
26
|
+
[:compressed_gas, :no_air] => "S",
|
27
|
+
[:hydrogen, :air] => "A",
|
28
|
+
[:hydrogen, :no_air] => "B",
|
29
|
+
[:multi_fuel, :air] => "M",
|
30
|
+
[:multi_fuel, :no_air] => "F",
|
31
|
+
[:petrol, :air] => "V",
|
32
|
+
[:petrol, :no_air] => "Z",
|
33
|
+
[:ethanol, :air] => "U",
|
34
|
+
[:ethanol, :no_air] => "X",
|
35
|
+
}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
data/lib/sipp/version.rb
CHANGED
data/lib/sipp.rb
CHANGED
@@ -48,6 +48,10 @@ module SIPP
|
|
48
48
|
end
|
49
49
|
require "sipp/code"
|
50
50
|
require "sipp/dictionary"
|
51
|
+
require "sipp/inverted"
|
52
|
+
require "sipp/inverted_dictionary"
|
53
|
+
require "sipp/extended"
|
54
|
+
require "sipp/extended_dictionary"
|
51
55
|
require 'i18n'
|
52
56
|
I18n.load_path += Dir[File.expand_path("config/locales") + "/*.yml"]
|
53
57
|
# I18n.available_locales = [:en, :ru]
|
data/sipp.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["max@buslaev.net"]
|
11
11
|
|
12
12
|
spec.summary = %q{SIPP aka ACRISS code dictionary}
|
13
|
-
spec.description = %q{Translates car SIPP codes into something meaningful}
|
13
|
+
spec.description = %q{Translates car SIPP/ACRISS codes into something meaningful}
|
14
14
|
spec.homepage = "https://github.com/austerlitz/sipp"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
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.8
|
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-11-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,7 +80,7 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
-
description: Translates car SIPP codes into something meaningful
|
83
|
+
description: Translates car SIPP/ACRISS codes into something meaningful
|
84
84
|
email:
|
85
85
|
- max@buslaev.net
|
86
86
|
executables: []
|
@@ -103,6 +103,10 @@ files:
|
|
103
103
|
- lib/sipp/code.rb
|
104
104
|
- lib/sipp/dictionary.rb
|
105
105
|
- lib/sipp/engine.rb
|
106
|
+
- lib/sipp/extended.rb
|
107
|
+
- lib/sipp/extended_dictionary.rb
|
108
|
+
- lib/sipp/inverted.rb
|
109
|
+
- lib/sipp/inverted_dictionary.rb
|
106
110
|
- lib/sipp/localiser.rb
|
107
111
|
- lib/sipp/version.rb
|
108
112
|
- sipp.gemspec
|