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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e823ae979f2ceef4999a253bf86f204dec06313e
4
- data.tar.gz: fd26206453b273c66c0fed4eddfa6d675be7d8a8
3
+ metadata.gz: a759acbd50e83cfbc4294f476ca21048c42286fb
4
+ data.tar.gz: 91df79cf3188f78777c1495002445c540e60d031
5
5
  SHA512:
6
- metadata.gz: f3661ba71eec6117c0056b3e1ffc124ffcdfb64d24e19542bdb66d5564f03113d70720b5eec6303503ff4512e90c6c4c10f0d858a70d9ffd74ce726cceb6e1c8
7
- data.tar.gz: 20c4cb082839d425516cd5d21abb955a883a0fc64cf92d61dd01b20e9510e3f49c28fb3e67b380ae1402484e0449ec9990649c8712b6b1842b1885bc850fdc82
6
+ metadata.gz: e699be1f95b5075a45b4b8b54fc1e1ea1c418c32e88e1a202e9659d4e5e1ec4dfa3bfd00ef803ff79555d858cb1acd831e767249381cae6a3dda4748905e3465
7
+ data.tar.gz: fbe654d6c318cbc133c7a43d60614a800135d093b62a3524eeaa26747f60e33183e108475925961e5048b8e754683f35a2a8560b38e50a2ec50c26217a0f863f
data/Gemfile CHANGED
@@ -5,4 +5,4 @@ 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', '~> 3.0'
8
+ gem 'activesupport', '~> 4.1'
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
- validate_transmission &&
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, TransmissionError, FuelACError
24
+ rescue CodeError, CategoryError, TypeError, TransmissionDriveError, FuelACError
25
25
  false
26
26
  end
27
27
 
28
28
  def category
29
- CATEGORY[code[0]] if valid?
29
+ validate_category
30
+ CATEGORY[code[0]]
31
+ rescue CategoryError => e
32
+ nil
30
33
  end
31
34
 
32
35
  def type
33
- TYPE[code[1]] if valid?
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
- TRANSMISSION[code[2]] if valid?
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
- FUEL_AC[code[3]] if valid?
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
- FUEL[code[3]] if valid?
85
+ validate_fuel_ac
86
+ FUEL[code[3]]
87
+ rescue FuelACError => e
88
+ nil
46
89
  end
47
90
 
48
91
  def ac
49
- AC[code[3]] if valid?
92
+ validate_fuel_ac
93
+ AC[code[3]]
94
+ rescue FuelACError => e
95
+ nil
50
96
  end
51
97
 
52
98
  def ac?
53
- if valid?
54
- 'Air' == ac ? true : false # TODO fix magic string
55
- else
56
- nil
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, transmission, fuel_ac].join(' - ')
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 validate_transmission
91
- if @code[2].blank? || !TRANSMISSION.keys.include?(@code[2])
92
- raise TransmissionError, :invalid_transmission
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
@@ -46,7 +46,7 @@ module SIPP
46
46
  'K' => 'Commercial Van/Truck',
47
47
  }
48
48
 
49
- TRANSMISSION = {
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
@@ -1,3 +1,3 @@
1
1
  module SIPP
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.3"
3
3
  end
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 TransmissionError < StandardError; end
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/all'
13
+ require 'active_support/core_ext/object'
14
14
  require "sipp/code"
15
15
  require "sipp/dictionary"
data/sipp.gemspec CHANGED
@@ -27,5 +27,5 @@ Gem::Specification.new do |spec|
27
27
  spec.add_development_dependency "rake", "~> 10.0"
28
28
  spec.add_development_dependency "rspec", "~> 3.0"
29
29
 
30
- spec.add_dependency "activesupport", "~> 3.0"
30
+ spec.add_dependency "activesupport", "~> 4.1"
31
31
  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.0
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-07-30 00:00:00.000000000 Z
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: '3.0'
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: '3.0'
68
+ version: '4.1'
69
69
  description: Translates car SIPP codes into something meaningful
70
70
  email:
71
71
  - max@buslaev.net