sipp 0.1.2 → 0.1.6

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: '086bb9e51ee12559956fba75a010b63e1e8a0f8f'
4
- data.tar.gz: 2f7d6032d53679caf7d565ec8cea564c1397026b
3
+ metadata.gz: 9cd7a87af83d4a601d88f62e8db3ecad8bf946b4
4
+ data.tar.gz: 8fc8999221846975d2de8ba8b9395b4ca20c6af5
5
5
  SHA512:
6
- metadata.gz: 004c5f4a0d1027c9327f76bf99ed7fd0609bdfe510b0e0f72b644bf1669fd4b1a3b5411e2129ea0b90f441ba53c3d6938b80746ecab108b26fe2aa567df3cedd
7
- data.tar.gz: 8e50c19a31002240c004dc11b702f81f1742e40755874f99017b2034ffe61df2db32b9582d1dceaed628223b42e8d2458f06affbfd17784865c81e42dbaa13bc
6
+ metadata.gz: 434b594842591b348e6dec6454086e50c5e7100b70f7726ed15311583954218a9243ad239b1c6b7d16260547f3aa5b8d84646022c50b95f6469a045f94ed32f8
7
+ data.tar.gz: 41f77d27e86a4f70a77f9b7b2f8bbab624f1197303c87dd6b4125a415b084a90820f37e9170221fbc544d55c95cd6dda0067c92b6515cc57e9decf3347b1dc9c
data/Gemfile CHANGED
@@ -5,4 +5,5 @@ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
5
5
  # Specify your gem's dependencies in sipp.gemspec
6
6
  gemspec
7
7
 
8
- gem 'activesupport', '~> 4.1'
8
+ gem 'i18n'
9
+
data/README.md CHANGED
@@ -24,17 +24,81 @@ Or install it yourself as:
24
24
  code = SIPP::Code.new 'CCMN'
25
25
  code.to_s # "Compact - 2/4 Door - Manual Unspecified Drive - Unspecified Fuel/Power Without Air"
26
26
 
27
+ code.category.to_s # Compact
28
+ code.type.to_s # 2/4 Door
29
+ code.transmission_drive.to_s # Manual Unspecified Drive
30
+ code.transmission.to_s # Manual
31
+ code.drive.to_s # Unspecified Drive
32
+ code.transmission_manual? # true
33
+ code.transmission_auto? # false
34
+ code.fuel_ac.to_s # Unspecified Fuel/Power Without Air
35
+ code.fuel.to_s # Unspecified Fuel/Power
36
+ code.ac.to_s # No Air
27
37
  code.ac? # false
28
38
  ```
29
39
  If the code is invalid, it will return `nil` on all checks.
30
40
 
41
+ If only some of the letters are valid, it will translate them:
42
+ ```ruby
43
+ code = SIPP::Code.new '**DR'
44
+ code.valid? # false
45
+ code.to_s # #N/A - #N/A - Auto AWD - Unspecified Fuel/Power With Air
46
+ ```
47
+
31
48
  Calling `code.validate!` will throw validation errors with exceptions.
32
49
 
50
+ ### #as_json
51
+ A convenient hash that lists car capabilities.
52
+ ```ruby
53
+ SIPP::Code.new('CCDD').as_json
54
+ {
55
+ category: :compact,
56
+ type: :two_four_door,
57
+ transmission: :auto,
58
+ drive: :awd,
59
+ fuel: :diesel,
60
+ ac: :air,
61
+ code: "CCDD"
62
+ }
63
+
64
+ ```
65
+
66
+ ## I18n
67
+
68
+ **NOTE**: a simpler version without i18n is kept in `v.1.4`, you can use it as `gem 'sipp', git: 'https://github.com/austerlitz/sipp.git', tag: 'v1.4'`
69
+
70
+ For more flexibility methods like `category`, `drive` etc. return a simple
71
+ Wrapper object to provide either symbol or an i18n-sed string.
72
+ Thus, when `#to_s` is implied, it will return a translated message.
73
+ For use in code or elsewhere, use `#to_sym`:
74
+ ```ruby
75
+ if :diesel == code.fuel.to_sym
76
+ puts 'This car has a diesel engine'
77
+ end
78
+ ```
79
+
80
+ _This seems to be not an elegant solution. If you have any ideas on improving it, please make a pull request._
81
+
82
+
83
+ You can override existing or add your own translations an put them under the
84
+ `sipp` scope:
85
+ ```yaml
86
+ ua:
87
+ sipp:
88
+ category:
89
+ mini: міні
90
+ type:
91
+ convertible: кабріолет
92
+ transmission:
93
+ manual: МКПП
94
+ auto: АКПП
95
+ ```
96
+
33
97
  ## TODO
34
- - add pseudo codes
35
- - add van codes
36
- - add i18n helpers or redo strings into symbols to be i18n-ised
37
- - add query methods for common checks (like `.diesel?` etc)
98
+ - [x] add i18n helpers or redo strings into symbols to be i18n-sed
99
+ - [ ] add pseudo codes
100
+ - [ ] add van codes
101
+ - [ ] add query methods for common checks (like `.diesel?` etc)
38
102
 
39
103
 
40
104
  ## Development
data/bin/console CHANGED
@@ -7,8 +7,8 @@ require "sipp"
7
7
  # with your gem easier. You can also use a different console, if you like.
8
8
 
9
9
  # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
10
+ require "pry"
11
+ Pry.start
12
12
 
13
- require "irb"
14
- IRB.start(__FILE__)
13
+ # require "irb"
14
+ # IRB.start(__FILE__)
@@ -0,0 +1,100 @@
1
+ en:
2
+ sipp:
3
+ category:
4
+ mini: Mini
5
+ mini_elite: Mini Elite
6
+ economy: Economy
7
+ economy_elite: Economy Elite
8
+ compact: Compact
9
+ compact_elite: Compact Elite
10
+ intermediate: Intermediate
11
+ intermediate_elite: Intermediate Elite
12
+ standard: Standard
13
+ standard_elite: Standard Elite
14
+ fullsize: Fullsize
15
+ fullsize_elite: Fullsize Elite
16
+ premium: Premium
17
+ premium_elite: Premium Elite
18
+ luxury: Luxury
19
+ luxury_elite: Luxury Elite
20
+ oversize: Oversize
21
+ special: Special
22
+
23
+ type:
24
+ two_three_door: 2-3 Door
25
+ two_four_door: 2/4 Door
26
+ four_five_door: 4-5 Door
27
+ wagon_estate: Wagon/Estate
28
+ passenger_van: Passenger Van
29
+ limousine_sedan: Limousine/Sedan
30
+ sport: Sport
31
+ convertible: Convertible
32
+ suv: SUV
33
+ open_air_all_terrain: Open Air All Terrain
34
+ special: Special
35
+ pick_up_2_door: Pick up (single/extended cab) 2 door
36
+ pick_up_4_door: Pick up (double cab) 4 door
37
+ special_offer_car: Special Offer Car
38
+ coupe: Coupe
39
+ monospace: Monospace
40
+ recreational_vehicle: Recreational Vehicle
41
+ motor_home: Motor Home
42
+ two_wheel_vehicle: 2 Wheel Vehicle
43
+ roadster: Roadster
44
+ crossover: Crossover
45
+ commercial: Commercial Van/Truck
46
+
47
+ transmission_drive:
48
+ manual_unspecified_drive: Manual Unspecified Drive
49
+ manual_4wd: Manual 4WD
50
+ manual_awd: Manual AWD
51
+ auto_unspecified_drive: Auto Unspecified Drive
52
+ auto_4wd: Auto 4WD
53
+ auto_awd: Auto AWD
54
+
55
+ transmission:
56
+ manual: Manual
57
+ auto: Auto
58
+
59
+ drive:
60
+ unspecified: Unspecified
61
+ four_wd: 4WD
62
+ awd: AWD
63
+
64
+ fuel_ac:
65
+ unspecified_air: Unspecified Fuel/Power With Air
66
+ unspecified_no_air: Unspecified Fuel/Power Without Air
67
+ diesel_air: Diesel Air
68
+ diesel_no_air: Diesel No Air
69
+ hybrid_air: Hybrid Air
70
+ hybrid_plug_in_air: Hybrid Plug in Air
71
+ electric_air: Electric (Distance < 250mi/400km) Air
72
+ electric_plus_air: Electric Plus (Distance ≥ 250mi/400km) Air
73
+ compressed_gas_air: LPG/Compressed Gas Air
74
+ compressed_gas_no_air: LPG/Compressed Gas No Air
75
+ hydrogen_air: Hydrogen Air
76
+ hydrogen_no_air: Hydrogen No Air
77
+ multi_fuel_air: Multi Fuel/Power Air
78
+ multi_fuel_no_air: Multi fuel/power No Air
79
+ petrol_air: Petrol Air
80
+ petrol_no_air: Petrol No Air
81
+ ethanol_air: Ethanol Air
82
+ ethanol_no_air: Ethanol No Air
83
+
84
+ fuel:
85
+ unspecified: Unspecified Fuel/Power
86
+ diesel: Diesel
87
+ hybrid: Hybrid
88
+ hybrid_plug_in: Hybrid Plug in
89
+ electric: Electric (Distance < 250mi/400km)
90
+ electric_plus: Electric Plus (Distance ≥ 250mi/400km)
91
+ compressed_gas: LPG/Compressed Gas
92
+ hydrogen: Hydrogen
93
+ multi_fuel: Multi fuel/power
94
+ petrol: Petrol
95
+ ethanol: Ethanol
96
+
97
+ ac:
98
+ air: Air
99
+ no_air: No Air
100
+
@@ -0,0 +1,100 @@
1
+ ru:
2
+ sipp:
3
+ category:
4
+ mini: мини
5
+ mini_elite: мини элит
6
+ economy: эконом
7
+ economy_elite: эконом элит
8
+ compact: компакт
9
+ compact_elite: компакт элит
10
+ intermediate: средний
11
+ intermediate_elite: средний элит
12
+ standard: стандартный
13
+ standard_elite: стандартный элит
14
+ fullsize: полноразмерный
15
+ fullsize_elite: полноразмерный элит
16
+ premium: премиум
17
+ premium_elite: premium элит
18
+ luxury: люкс
19
+ luxury_elite: люкс элит
20
+ oversize: оверсайз
21
+ special: специальный
22
+
23
+ type:
24
+ two_three_door: 2-3 двери
25
+ two_four_door: 2/4 двери
26
+ four_five_door: 4-5 двери
27
+ wagon_estate: универсал
28
+ passenger_van: пассажирский фургон
29
+ limousine_sedan: седан
30
+ sport: спорт
31
+ convertible: кабриолет
32
+ suv: SUV
33
+ open_air_all_terrain: внедорожник
34
+ special: специального назначения
35
+ pick_up_2_door: двухдверный пикап
36
+ pick_up_4_door: четырехдверный пикап
37
+ special_offer_car: автомобиль спецпредложения
38
+ coupe: купе
39
+ monospace: однообъемник
40
+ recreational_vehicle: автомобиль для отдыха
41
+ motor_home: дом на колесах
42
+ two_wheel_vehicle: двухколесное транспортное средство
43
+ roadster: родстер
44
+ crossover: кроссовер
45
+ commercial: коммерческий фургон
46
+
47
+ transmission_drive:
48
+ manual_unspecified_drive: МКПП, привод не указан
49
+ manual_4wd: МКПП, 4WD
50
+ manual_awd: МКПП, AWD
51
+ auto_unspecified_drive: АКПП, привод не указан
52
+ auto_4wd: АКПП, 4WD
53
+ auto_awd: АКПП, AWD
54
+
55
+ transmission:
56
+ manual: МКПП
57
+ auto: АКПП
58
+
59
+ drive:
60
+ unspecified: привод не указан
61
+ four_wd: 4WD
62
+ awd: AWD
63
+
64
+ fuel_ac:
65
+ unspecified_air: топливо не указано, кондиционер
66
+ unspecified_no_air: топливо не указано, без кондиционера
67
+ diesel_air: дизель, кондиционер
68
+ diesel_no_air: дизель, без кондиционера
69
+ hybrid_air: гибрид, кондиционер
70
+ hybrid_plug_in_air: гибрид с подзарядкой, кондиционер
71
+ electric_air: электрический (до 250 миль/400 км), кондиционер
72
+ electric_plus_air: электрический плюс (от 250 миль/400 км), кондиционер
73
+ compressed_gas_air: сжиженный газ, кондиционер
74
+ compressed_gas_no_air: сжиженный газ, без кондиционера
75
+ hydrogen_air: водород, кондиционер
76
+ hydrogen_no_air: водород, без кондиционера
77
+ multi_fuel_air: мультитопливный, кондиционер
78
+ multi_fuel_no_air: мультитопливный, без кондиционера
79
+ petrol_air: бензин, кондиционер
80
+ petrol_no_air: бензин, без кондиционера
81
+ ethanol_air: спирт, кондиционер
82
+ ethanol_no_air: спирт, без кондиционера
83
+
84
+ fuel:
85
+ unspecified: топливо не указано
86
+ diesel: дизель
87
+ hybrid: гибрид
88
+ hybrid_plug_in: гибрид с подзарядкой
89
+ electric: электрический (до 250 миль/400 км)
90
+ electric_plus: электрический плюс (от 250 миль/400 км)
91
+ compressed_gas: сжиженный газ
92
+ hydrogen: водород
93
+ multi_fuel: мультитопливный
94
+ petrol: бензин
95
+ ethanol: спирт
96
+
97
+ ac:
98
+ air: кондиционер
99
+ no_air: без кондиционера
100
+
data/lib/sipp/code.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'sipp/dictionary'
2
+ require 'sipp/localiser'
2
3
 
3
4
  module SIPP
4
5
  class Code
@@ -26,67 +27,96 @@ module SIPP
26
27
  end
27
28
 
28
29
  def category
29
- CATEGORY[code[0]] if valid?
30
+ validate_category
31
+ Category.new CATEGORY[code[0]]
32
+ rescue CategoryError => e
33
+ nil
30
34
  end
31
35
 
32
36
  def type
33
- TYPE[code[1]] if valid?
37
+ validate_type
38
+ Type.new TYPE[code[1]]
39
+ rescue TypeError => e
40
+ nil
34
41
  end
35
42
 
36
43
  def transmission_drive
37
- TRANSMISSION_DRIVE[code[2]] if valid?
44
+ validate_transmission_drive
45
+ TransmissionDrive.new TRANSMISSION_DRIVE[code[2]]
46
+ rescue TransmissionDriveError => e
47
+ nil
38
48
  end
39
49
 
40
50
  def transmission
41
- TRANSMISSION[code[2]] if valid?
51
+ validate_transmission_drive
52
+ Transmission.new TRANSMISSION[code[2]]
53
+ rescue TransmissionDriveError => e
54
+ nil
42
55
  end
43
56
 
44
57
  def transmission_manual?
45
- if valid?
46
- 'Manual' == transmission ? true : false # TODO fix magic string
47
- else
48
- nil
49
- end
58
+ validate_transmission_drive
59
+ :manual == transmission.to_sym ? true : false
60
+ rescue TransmissionDriveError => e
61
+ nil
50
62
  end
63
+
51
64
  def transmission_auto?
52
- if valid?
53
- 'Auto' == transmission ? true : false # TODO fix magic string
54
- else
55
- nil
56
- end
65
+ validate_transmission_drive
66
+ :auto == transmission.to_sym ? true : false
67
+ rescue TransmissionDriveError => e
68
+ nil
57
69
  end
70
+
58
71
  def drive
59
- DRIVE[code[2]] if valid?
72
+ validate_transmission_drive
73
+ Drive.new DRIVE[code[2]]
74
+ rescue TransmissionDriveError => e
75
+ nil
60
76
  end
61
77
 
62
78
  def fuel_ac
63
- FUEL_AC[code[3]] if valid?
79
+ validate_fuel_ac
80
+ FuelAC.new FUEL_AC[code[3]]
81
+ rescue FuelACError => e
82
+ nil
64
83
  end
65
84
 
66
85
  def fuel
67
- FUEL[code[3]] if valid?
86
+ validate_fuel_ac
87
+ Fuel.new FUEL[code[3]]
88
+ rescue FuelACError => e
89
+ nil
68
90
  end
69
91
 
70
92
  def ac
71
- AC[code[3]] if valid?
93
+ validate_fuel_ac
94
+ Ac.new AC[code[3]]
95
+ rescue FuelACError => e
96
+ nil
72
97
  end
73
98
 
74
99
  def ac?
75
- if valid?
76
- 'Air' == ac ? true : false # TODO fix magic string
77
- else
78
- nil
79
- end
100
+ validate_fuel_ac
101
+ :air == ac.to_sym ? true : false
102
+ rescue FuelACError => e
103
+ nil
80
104
  end
81
105
 
82
106
  def to_s
83
- [category, type, transmission_drive, fuel_ac].join(' - ') if valid?
107
+ [category, type, transmission_drive, fuel_ac].map{|c| c.nil? ? '#N/A' : c}.join(' - ')
108
+ rescue CodeError, CategoryError, TypeError, TransmissionDriveError, FuelACError
109
+ ''
110
+ end
111
+
112
+ def as_json(options = nil)
113
+ [category, type, transmission, drive, fuel, ac].map(&:as_json).inject(&:merge).merge({code: @code})
84
114
  end
85
115
 
86
116
  private
87
117
 
88
118
  def validate_code
89
- if @code.blank? || 4 != @code.length
119
+ if !@code || @code.empty? || 4 != @code.length
90
120
  raise CodeError, :invalid_code
91
121
  else
92
122
  true
@@ -94,7 +124,7 @@ module SIPP
94
124
  end
95
125
 
96
126
  def validate_category
97
- if @code[0].blank? || !CATEGORY.keys.include?(@code[0])
127
+ if !@code[0] || @code[0].empty? || !CATEGORY.keys.include?(@code[0])
98
128
  raise CategoryError, :invalid_category
99
129
  else
100
130
  true
@@ -102,7 +132,7 @@ module SIPP
102
132
  end
103
133
 
104
134
  def validate_type
105
- if @code[1].blank? || !TYPE.keys.include?(@code[1])
135
+ if !@code[1] || @code[1].empty? || !TYPE.keys.include?(@code[1])
106
136
  raise TypeError, :invalid_type
107
137
  else
108
138
  true
@@ -110,7 +140,7 @@ module SIPP
110
140
  end
111
141
 
112
142
  def validate_transmission_drive
113
- if @code[2].blank? || !TRANSMISSION_DRIVE.keys.include?(@code[2])
143
+ if !@code[2] || @code[2].empty? || !TRANSMISSION_DRIVE.keys.include?(@code[2])
114
144
  raise TransmissionDriveError, :invalid_transmission_drive
115
145
  else
116
146
  true
@@ -118,7 +148,7 @@ module SIPP
118
148
  end
119
149
 
120
150
  def validate_fuel_ac
121
- if @code[3].blank? || !FUEL_AC.keys.include?(@code[3])
151
+ if !@code[3] || @code[3].empty? || !FUEL_AC.keys.include?(@code[3])
122
152
  raise FuelACError, :invalid_fuel_ac
123
153
  else
124
154
  true
@@ -1,138 +1,138 @@
1
1
  module SIPP
2
2
  module Dictionary
3
3
  CATEGORY = {
4
- 'M' => 'Mini',
5
- 'N' => 'Mini Elite',
6
- 'E' => 'Economy',
7
- 'H' => 'Economy Elite',
8
- 'C' => 'Compact',
9
- 'D' => 'Compact Elite',
10
- 'I' => 'Intermediate',
11
- 'J' => 'Intermediate Elite',
12
- 'S' => 'Standard',
13
- 'R' => 'Standard Elite',
14
- 'F' => 'Fullsize',
15
- 'G' => 'Fullsize Elite',
16
- 'P' => 'Premium',
17
- 'U' => 'Premium Elite',
18
- 'L' => 'Luxury',
19
- 'W' => 'Luxury Elite',
20
- 'O' => 'Oversize',
21
- 'X' => 'Special',
4
+ 'M' => :mini,
5
+ 'N' => :mini_elite,
6
+ 'E' => :economy,
7
+ 'H' => :economy_elite,
8
+ 'C' => :compact,
9
+ 'D' => :compact_elite,
10
+ 'I' => :intermediate,
11
+ 'J' => :intermediate_elite,
12
+ 'S' => :standard,
13
+ 'R' => :standard_elite,
14
+ 'F' => :fullsize,
15
+ 'G' => :fullsize_elite,
16
+ 'P' => :premium,
17
+ 'U' => :premium_elite,
18
+ 'L' => :luxury,
19
+ 'W' => :luxury_elite,
20
+ 'O' => :oversize,
21
+ 'X' => :special,
22
22
  }
23
23
 
24
24
  TYPE = {
25
- 'B' => '2-3 Door',
26
- 'C' => '2/4 Door',
27
- 'D' => '4-5 Door',
28
- 'W' => 'Wagon/Estate',
29
- 'V' => 'Passenger Van',
30
- 'L' => 'Limousine/Sedan',
31
- 'S' => 'Sport',
32
- 'T' => 'Convertible',
33
- 'F' => 'SUV',
34
- 'J' => 'Open Air All Terrain',
35
- 'X' => 'Special',
36
- 'P' => 'Pick up (single/extended cab) 2 door',
37
- 'Q' => 'Pick up (double cab) 4 door',
38
- 'Z' => 'Special Offer Car',
39
- 'E' => 'Coupe',
40
- 'M' => 'Monospace',
41
- 'R' => 'Recreational Vehicle',
42
- 'H' => 'Motor Home',
43
- 'Y' => '2 Wheel Vehicle',
44
- 'N' => 'Roadster',
45
- 'G' => 'Crossover',
46
- 'K' => 'Commercial Van/Truck',
25
+ 'B' => :two_three_door,
26
+ 'C' => :two_four_door,
27
+ 'D' => :four_five_door,
28
+ 'W' => :wagon_estate,
29
+ 'V' => :passenger_van,
30
+ 'L' => :limousine_sedan,
31
+ 'S' => :sport,
32
+ 'T' => :convertible,
33
+ 'F' => :sUV,
34
+ 'J' => :open_air_all_terrain,
35
+ 'X' => :special,
36
+ 'P' => :pick_up_2_door,
37
+ 'Q' => :pick_up_4_door,
38
+ 'Z' => :special_offer_car,
39
+ 'E' => :coupe,
40
+ 'M' => :monospace,
41
+ 'R' => :recreational_vehicle,
42
+ 'H' => :motor_home,
43
+ 'Y' => :two_wheel_vehicle,
44
+ 'N' => :roadster,
45
+ 'G' => :crossover,
46
+ 'K' => :commercial,
47
47
  }
48
48
 
49
49
  TRANSMISSION_DRIVE = {
50
- 'M' => 'Manual Unspecified Drive',
51
- 'N' => 'Manual 4WD',
52
- 'C' => 'Manual AWD',
53
- 'A' => 'Auto Unspecified Drive',
54
- 'B' => 'Auto 4WD',
55
- 'D' => 'Auto AWD',
50
+ 'M' => :manual_unspecified_drive,
51
+ 'N' => :manual_4wd,
52
+ 'C' => :manual_awd,
53
+ 'A' => :auto_unspecified_drive,
54
+ 'B' => :auto_4wd,
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',
57
+ TRANSMISSION = {
58
+ 'M' => :manual,
59
+ 'N' => :manual,
60
+ 'C' => :manual,
61
+ 'A' => :auto,
62
+ 'B' => :auto,
63
+ 'D' => :auto,
64
64
  }
65
65
 
66
66
  DRIVE = {
67
- 'M' => 'Unspecified',
68
- 'N' => '4WD',
69
- 'C' => 'AWD',
70
- 'A' => 'Unspecified',
71
- 'B' => '4WD',
72
- 'D' => 'AWD',
67
+ 'M' => :unspecified,
68
+ 'N' => :four_wd,
69
+ 'C' => :awd,
70
+ 'A' => :unspecified,
71
+ 'B' => :four_wd,
72
+ 'D' => :awd,
73
73
  }
74
74
 
75
75
  FUEL_AC = {
76
- 'R' => 'Unspecified Fuel/Power With Air',
77
- 'N' => 'Unspecified Fuel/Power Without Air',
78
- 'D' => 'Diesel Air',
79
- 'Q' => 'Diesel No Air',
80
- 'H' => 'Hybrid Air',
81
- 'I' => 'Hybrid Plug in Air',
82
- 'E' => 'Electric (Distance < 250mi/400km) Air',
83
- 'C' => 'Electric Plus (Distance ≥ 250mi/400km) Air',
84
- 'L' => 'LPG/Compressed Gas Air',
85
- 'S' => 'LPG/Compressed Gas No Air',
86
- 'A' => 'Hydrogen Air',
87
- 'B' => 'Hydrogen No Air',
88
- 'M' => 'Multi Fuel/Power Air',
89
- 'F' => 'Multi fuel/power No Air',
90
- 'V' => 'Petrol Air',
91
- 'Z' => 'Petrol No Air',
92
- 'U' => 'Ethanol Air',
93
- 'X' => 'Ethanol No Air',
76
+ 'R' => :unspecified_air,
77
+ 'N' => :unspecified_no_air,
78
+ 'D' => :diesel_air,
79
+ 'Q' => :diesel_no_air,
80
+ 'H' => :hybrid_air,
81
+ 'I' => :hybrid_plug_in_air,
82
+ 'E' => :electric_air,
83
+ 'C' => :electric_plus_air,
84
+ 'L' => :compressed_gas_air,
85
+ 'S' => :compressed_gas_no_air,
86
+ 'A' => :hydrogen_air,
87
+ 'B' => :hydrogen_no_air,
88
+ 'M' => :multi_fuel_air,
89
+ 'F' => :multi_fuel_no_air,
90
+ 'V' => :petrol_air,
91
+ 'Z' => :petrol_no_air,
92
+ 'U' => :ethanol_air,
93
+ 'X' => :ethanol_no_air
94
94
  }
95
95
 
96
96
  FUEL = {
97
- 'R' => 'Unspecified Fuel/Power',
98
- 'N' => 'Unspecified Fuel/Power',
99
- 'D' => 'Diesel',
100
- 'Q' => 'Diesel',
101
- 'H' => 'Hybrid',
102
- 'I' => 'Hybrid Plug in',
103
- 'E' => 'Electric (Distance < 250mi/400km)',
104
- 'C' => 'Electric Plus (Distance ≥ 250mi/400km)',
105
- 'L' => 'LPG/Compressed Gas',
106
- 'S' => 'LPG/Compressed Gas',
107
- 'A' => 'Hydrogen',
108
- 'B' => 'Hydrogen',
109
- 'M' => 'Multi Fuel/Power',
110
- 'F' => 'Multi fuel/power',
111
- 'V' => 'Petrol',
112
- 'Z' => 'Petrol',
113
- 'U' => 'Ethanol',
114
- 'X' => 'Ethanol',
97
+ 'R' => :unspecified,
98
+ 'N' => :unspecified,
99
+ 'D' => :diesel,
100
+ 'Q' => :diesel,
101
+ 'H' => :hybrid,
102
+ 'I' => :hybrid_plug_in,
103
+ 'E' => :electric,
104
+ 'C' => :electric_plus,
105
+ 'L' => :compressed_gas,
106
+ 'S' => :compressed_gas,
107
+ 'A' => :hydrogen,
108
+ 'B' => :hydrogen,
109
+ 'M' => :multi_fuel,
110
+ 'F' => :multi_fuel,
111
+ 'V' => :petrol,
112
+ 'Z' => :petrol,
113
+ 'U' => :ethanol,
114
+ 'X' => :ethanol
115
115
  }
116
116
 
117
117
  AC = {
118
- 'R' => 'Air',
119
- 'N' => 'No Air',
120
- 'D' => 'Air',
121
- 'Q' => 'No Air',
122
- 'H' => 'Air',
123
- 'I' => 'Air',
124
- 'E' => 'Air',
125
- 'C' => 'Air',
126
- 'L' => 'Air',
127
- 'S' => 'No Air',
128
- 'A' => 'Air',
129
- 'B' => 'No Air',
130
- 'M' => 'Air',
131
- 'F' => 'No Air',
132
- 'V' => 'Air',
133
- 'Z' => 'No Air',
134
- 'U' => 'Air',
135
- 'X' => 'No Air',
118
+ 'R' => :air,
119
+ 'N' => :no_air,
120
+ 'D' => :air,
121
+ 'Q' => :no_air,
122
+ 'H' => :air,
123
+ 'I' => :air,
124
+ 'E' => :air,
125
+ 'C' => :air,
126
+ 'L' => :air,
127
+ 'S' => :no_air,
128
+ 'A' => :air,
129
+ 'B' => :no_air,
130
+ 'M' => :air,
131
+ 'F' => :no_air,
132
+ 'V' => :air,
133
+ 'Z' => :no_air,
134
+ 'U' => :air,
135
+ 'X' => :no_air
136
136
  }
137
137
  end
138
138
  end
@@ -0,0 +1,8 @@
1
+ module SIPP
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace SIPP
4
+ initializer 'SIPP', before: :load_config_initializers do
5
+ Rails.application.config.i18n.load_path += Dir["#{config.root}/config/locales/**/*.yml"]
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module SIPP
2
+ module Localiser
3
+ def translate(scope, item)
4
+ I18n.translate("sipp.#{scope}.#{item}")
5
+ end
6
+ alias_method :t, :translate
7
+ end
8
+ end
data/lib/sipp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module SIPP
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.6"
3
3
  end
data/lib/sipp.rb CHANGED
@@ -1,15 +1,56 @@
1
1
  require "sipp/version"
2
2
 
3
+ require "sipp/localiser"
3
4
  module SIPP
4
- class Error < StandardError; end
5
- class CodeError < StandardError; end
6
- class CategoryError < StandardError; end
7
- class TypeError < StandardError; end
8
- class TransmissionDriveError < StandardError; end
9
- class FuelACError < StandardError; end
10
- # Your code goes here...
11
- end
5
+ Error = Class.new StandardError
6
+ CodeError = Class.new Error
7
+ CategoryError = Class.new Error
8
+ TypeError = Class.new Error
9
+ TransmissionDriveError = Class.new Error
10
+ FuelACError = Class.new Error
11
+
12
+ class SIPPCodeWrapper
13
+ include Localiser
14
+
15
+ def initialize(symbol)
16
+ @sym = symbol
17
+ end
18
+
19
+ def to_s
20
+ t klass_name, @sym
21
+ end
22
+
23
+ def klass_name
24
+ self.class.name.split('::').last
25
+ .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
26
+ .gsub(/([a-z\d])([A-Z])/, '\1_\2')
27
+ .tr(' ', '_')
28
+ .downcase
29
+ end
12
30
 
13
- require 'active_support/core_ext/object'
31
+ def to_sym
32
+ @sym
33
+ end
34
+
35
+ def as_json
36
+ { klass_name.to_sym => @sym }
37
+ end
38
+ end
39
+
40
+ Category = Class.new SIPPCodeWrapper
41
+ Type = Class.new SIPPCodeWrapper
42
+ TransmissionDrive = Class.new SIPPCodeWrapper
43
+ Transmission = Class.new SIPPCodeWrapper
44
+ Drive = Class.new SIPPCodeWrapper
45
+ FuelAC = Class.new SIPPCodeWrapper
46
+ Fuel = Class.new SIPPCodeWrapper
47
+ Ac = Class.new SIPPCodeWrapper
48
+ end
14
49
  require "sipp/code"
15
- require "sipp/dictionary"
50
+ require "sipp/dictionary"
51
+ require 'i18n'
52
+ I18n.load_path += Dir[File.expand_path("config/locales") + "/*.yml"]
53
+ # I18n.available_locales = [:en, :ru]
54
+ if defined?(Rails)
55
+ require 'sipp/engine'
56
+ end
data/sipp.gemspec CHANGED
@@ -26,6 +26,7 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency "bundler", "~> 1.17"
27
27
  spec.add_development_dependency "rake", "~> 10.0"
28
28
  spec.add_development_dependency "rspec", "~> 3.0"
29
+ spec.add_development_dependency "pry"
29
30
 
30
- spec.add_dependency "activesupport", "~> 4.1"
31
+ spec.add_dependency "i18n"
31
32
  end
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.2
4
+ version: 0.1.6
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-07-31 00:00:00.000000000 Z
11
+ date: 2022-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -53,19 +53,33 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: activesupport
56
+ name: pry
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
60
67
  - !ruby/object:Gem::Version
61
- version: '4.1'
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: i18n
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
62
76
  type: :runtime
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
- - - "~>"
80
+ - - ">="
67
81
  - !ruby/object:Gem::Version
68
- version: '4.1'
82
+ version: '0'
69
83
  description: Translates car SIPP codes into something meaningful
70
84
  email:
71
85
  - max@buslaev.net
@@ -83,9 +97,13 @@ files:
83
97
  - Rakefile
84
98
  - bin/console
85
99
  - bin/setup
100
+ - config/locales/en.yml
101
+ - config/locales/ru.yml
86
102
  - lib/sipp.rb
87
103
  - lib/sipp/code.rb
88
104
  - lib/sipp/dictionary.rb
105
+ - lib/sipp/engine.rb
106
+ - lib/sipp/localiser.rb
89
107
  - lib/sipp/version.rb
90
108
  - sipp.gemspec
91
109
  homepage: https://github.com/austerlitz/sipp