maverick_vin_parser 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'maverick_vin_parser'
4
+
5
+ if ARGV.length != 1
6
+ puts 'usage: maverick_vin_parser VIN'
7
+ exit(0)
8
+ end
9
+
10
+
11
+ begin
12
+ puts MaverickVinParser.new.parse(ARGV[0])
13
+ rescue MaverickVinParser::ArgumentError
14
+ puts $!.message
15
+ end
@@ -0,0 +1,43 @@
1
+ require 'vin_constants'
2
+
3
+
4
+ class MaverickVinParser
5
+
6
+ include VinConstants
7
+
8
+ ArgumentError = Class.new(ArgumentError)
9
+
10
+ def initialize
11
+ plant_code_regex = list_to_regex(PLANT_CODES)
12
+ body_code_regex = list_to_regex(BODY_CODES)
13
+ engine_code_regex = list_to_regex(ENGINE_CODES)
14
+ @regex_main = /([0-7])(#{plant_code_regex})(#{body_code_regex})(#{engine_code_regex})([0-9]{6})/
15
+ end
16
+
17
+ def parse(vin)
18
+ @regex_main.match(vin) do
19
+ return {
20
+ year: 1970+$1.to_i,
21
+ plant: PLANT_CODES[$2.to_sym],
22
+ body: BODY_CODES[$3],
23
+ engine: ENGINE_CODES[$4.to_sym],
24
+ unit_number: $5.to_i
25
+ }
26
+ end
27
+
28
+
29
+ raise ArgumentError.new("#{vin} does not appear to be a valid Maverick VIN")
30
+
31
+
32
+ end
33
+
34
+ private
35
+
36
+ def list_to_regex(list)
37
+ keys = list.keys
38
+ keys.collect! { |key| key.length > 1 ? "(?:#{key})" : key }
39
+ /#{keys.join('|')}/
40
+ end
41
+
42
+
43
+ end
@@ -0,0 +1,36 @@
1
+ module VinConstants
2
+
3
+ PLANT_CODES = { A: 'Atlanta',
4
+ B: 'Oakville Canada',
5
+ E: 'Mahwah',
6
+ F: 'Dearborn',
7
+ G: 'Chicago',
8
+ H: 'Lorain',
9
+ J: 'Los Angeles',
10
+ K: 'Kansas City',
11
+ N: 'Norfolk',
12
+ P: 'Twin Cities',
13
+ R: 'San Jose',
14
+ S: 'Allen Park - Pilot',
15
+ T: 'Metuchen',
16
+ U: 'Louisville',
17
+ W: 'Wayne',
18
+ X: 'St. Thomas',
19
+ Y: 'Wixom',
20
+ Z: 'St. Louis'
21
+ }
22
+
23
+ BODY_CODES = { '91' => 'Maverick 2-Door Sedan Standard',
24
+ '92' => 'Maverick 4-Door Sedan Standard',
25
+ '93' => 'Maverick 2-Door Sport Sedan Grabber',
26
+ '30' => 'Comet 4-Door Sedan Standard',
27
+ '31' => 'Comet 2-Door Sedan Standard or GT'
28
+ }
29
+
30
+ ENGINE_CODES = { U: '170ci 6-Cylinder 1 bbl',
31
+ T: '200ci 6-Cylinder 1 bbl',
32
+ L: '250ci 6-Cylinder 1 bbl',
33
+ F: '302ci 8-Cylinder 2 bbl'
34
+ }
35
+
36
+ end
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: maverick_vin_parser
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Byron Appelt
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-06-12 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: A parser for Vehicle Identification Numbers from Ford Mavericks and Mercury
15
+ Comets 1970-77
16
+ email: byron.appelt@gmail.com
17
+ executables:
18
+ - maverick_vin_parser
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - lib/maverick_vin_parser.rb
23
+ - lib/vin_constants.rb
24
+ - bin/maverick_vin_parser
25
+ homepage: http://rubygems.org/gems/maverick_vin_parser
26
+ licenses: []
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ none: false
33
+ requirements:
34
+ - - ! '>='
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ! '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ requirements: []
44
+ rubyforge_project:
45
+ rubygems_version: 1.8.25
46
+ signing_key:
47
+ specification_version: 3
48
+ summary: VIN parser for Ford Mavericks
49
+ test_files: []