sipp 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9cd7a87af83d4a601d88f62e8db3ecad8bf946b4
4
- data.tar.gz: 8fc8999221846975d2de8ba8b9395b4ca20c6af5
3
+ metadata.gz: 950a78c54189d24a5d4a9159c2c83d74647b867b
4
+ data.tar.gz: 3a25d2e6be0a30821d1473db85ae7b31048cd2af
5
5
  SHA512:
6
- metadata.gz: 434b594842591b348e6dec6454086e50c5e7100b70f7726ed15311583954218a9243ad239b1c6b7d16260547f3aa5b8d84646022c50b95f6469a045f94ed32f8
7
- data.tar.gz: 41f77d27e86a4f70a77f9b7b2f8bbab624f1197303c87dd6b4125a415b084a90820f37e9170221fbc544d55c95cd6dda0067c92b6515cc57e9decf3347b1dc9c
6
+ metadata.gz: a12870aa3d1ee2edba06d09015d08a9b708ab23c61cbafc62293f253f8a4217f87af052b2a41aeb3ff415fe126237364e08580bdd01a67c0037ae4ec48c965f4
7
+ data.tar.gz: 87a73c7cd626016cb6e473584d3ca2c0ad04e564089c785b79d7cf58064b46fa5252eaf59051eab50931aacac4fc24179d448968ce5c820dcb4f6036dea02adb
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
@@ -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
@@ -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
@@ -30,7 +30,7 @@ module SIPP
30
30
  'L' => :limousine_sedan,
31
31
  'S' => :sport,
32
32
  'T' => :convertible,
33
- 'F' => :sUV,
33
+ 'F' => :suv,
34
34
  'J' => :open_air_all_terrain,
35
35
  'X' => :special,
36
36
  'P' => :pick_up_2_door,
@@ -0,0 +1,109 @@
1
+ require 'sipp/extended_dictionary'
2
+ module SIPP
3
+
4
+ class Extended
5
+ include ExtendedDictionary
6
+
7
+ def self.generate(capabilities)
8
+ category = CATEGORY[capabilities[:category]]
9
+ type = TYPE[capabilities[:type]]
10
+ transmission = TRANSMISSION[capabilities[:transmission]]
11
+ drive = DRIVE[capabilities[:drive]]
12
+ fuel = FUEL[capabilities[:fuel]]
13
+ ac = AC[capabilities[:ac]]
14
+ capabilities[:bags_big] = capabilities.delete(:bags) unless capabilities[:bags].nil?
15
+ %i[doors seats bags_big bags_small].each do |cap|
16
+ capabilities[cap] = nil if :unspecified == capabilities[cap]
17
+ end
18
+
19
+ [
20
+ category, type, transmission, drive, fuel, ac,
21
+ capabilities[:doors],
22
+ capabilities[:seats],
23
+ (capabilities[:bags_big] || capabilities[:bags]),
24
+ capabilities[:bags_small],
25
+ ].map{|cap| cap || '*'}.join
26
+ end
27
+
28
+
29
+ attr_reader :code
30
+ def initialize(code = nil)
31
+ @code = code.to_s.strip.upcase
32
+ .ljust(10, '*') # pad everything absent as :unspecified
33
+ end
34
+
35
+
36
+
37
+ def category
38
+ Category.new CATEGORY.invert[code[0]]
39
+ end
40
+
41
+ def type
42
+ Type.new TYPE.invert[code[1]]
43
+ end
44
+
45
+ def transmission
46
+ Transmission.new TRANSMISSION.invert[code[2]]
47
+ end
48
+ def drive
49
+ Drive.new DRIVE.invert[code[3]]
50
+ end
51
+ def fuel
52
+ Fuel.new FUEL.invert[code[4]]
53
+ end
54
+ def ac
55
+ Ac.new AC.invert[code[5]]
56
+ end
57
+ def doors
58
+ result = code[6]&.to_i
59
+ if result.zero?
60
+ :unspecified
61
+ else
62
+ result
63
+ end
64
+ end
65
+ def seats
66
+ result = code[7]&.to_i
67
+ if result.zero?
68
+ :unspecified
69
+ else
70
+ result
71
+ end
72
+ end
73
+ def bags
74
+ result = code[8]&.to_i
75
+ if result.zero?
76
+ :unspecified
77
+ else
78
+ result
79
+ end
80
+ end
81
+ alias_method :bags_big, :bags
82
+ def bags_small
83
+ result = code[9]&.to_i
84
+ if result.zero?
85
+ :unspecified
86
+ else
87
+ result
88
+ end
89
+ end
90
+
91
+ def to_s
92
+ [
93
+ category, type, transmission, drive, fuel, ac,
94
+ doors, seats, bags_big, bags_small,
95
+ ].join(Code::SEPARATOR)
96
+ end
97
+
98
+ def as_json(options = nil)
99
+
100
+ [category, type, transmission, drive, fuel, ac].compact.map(&:as_json).inject(&:merge).merge(
101
+ {
102
+ doors: doors,
103
+ seats: seats,
104
+ bags_big: bags,
105
+ bags_small: bags_small
106
+ })
107
+ end
108
+ end
109
+ 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
@@ -1,3 +1,3 @@
1
1
  module SIPP
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
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]
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.6
4
+ version: 0.1.7
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-08-16 00:00:00.000000000 Z
11
+ date: 2022-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -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